SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Location
    Belgium
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Datagrid problems(VB.net and MySQL)

    Hi,

    I didn't really know where to post, here or database so I posted it here(sorry if it's wrong!)

    I'm trying to connect to a mysql database with vb.net(visual studio 2008), I can connect, load data in a datagrid and everything but when I fill my datagrid, my tables are set by itself possible to set the columns names manual and put data in the predefined columns? My second problem is how to change a column type, in my database I've got my datetime values in integer, I've got a code to convert it to date time but I get an error to change the value, the error is something similar to "Column type is int64 and not Date"

    This is my code
    Code:
    Imports MySql.Data.MySqlClient
    
    Public Class frmOrderoverzicht
    
        Dim conn As MySqlConnection
        Dim data As DataTable
        Dim Adapter As MySqlDataAdapter
        Dim CommandBuild As MySqlCommandBuilder
    
        Private Sub frmOrderoverzicht_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim connStr As String
            connStr = "server=localhost;user id=root; password=; database=mysql; pooling=false"
            conn = New MySqlConnection(connStr)
    
            Try
                conn.Open()
                conn.ChangeDatabase("orders")
    
                data = New DataTable
                Adapter = New MySqlDataAdapter("SELECT `ordernr`, `orderdatum`, `klantnaam`, `omschrijving` FROM `order`".ToString, conn)
                CommandBuild = New MySqlCommandBuilder(Adapter)
                Adapter.Fill(data)
    
                dgrOrders.DataSource = data
            Catch ex As MySqlException
                MessageBox.Show("Er is een probleem opgetreden: " + ex.Message)
            End Try
    
        End Sub
    End Class

  2. #2
    SitePoint Zealot
    Join Date
    Mar 2005
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    check the autogeneratecolumns property of the datagrid

    i believe you can use datetime.parse(), or something like that. check out the datetime object, or maybe its the date object. but basically youll have to convert the integer to datetime before binding, or do it in the onitemcreated event(or some other event before display)
    Web Application Development & Maintenance

  3. #3
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Location
    Belgium
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the problem is I'm not familiar with this, I've just read some tutorials how to display it with mysql. So I have no idea how to convert it before putting it in any column. I thought it was going to be like php but it's totally not.

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Location
    Belgium
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    any help? please

  5. #5
    SitePoint Wizard
    Join Date
    Feb 2007
    Posts
    1,274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  6. #6
    SitePoint Enthusiast
    Join Date
    Nov 2007
    Location
    Belgium
    Posts
    60
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks I'll have a look

    Got another question, I've added a button to the datagrid but when I push it it should give a new form but how can I add this or call this event?
    Last edited by slisebry; Jun 5, 2008 at 14:15.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •