Results 1 to 4 of 4

Thread: how do u Insert Datatable to Mysql server ?

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    12

    how do u Insert Datatable to Mysql server ?

    I wish to insert a filled datatable to a mySQL table, the coloum names are the same in the tabletable as the mySQL table (name,guid,count) but i am unsure how to do it. i already have a connection string and a mySQLdataAdapter, but just not sure how to use them for inserting lol.

    Code:
                Dim Adapter As MySqlDataAdapter
                Dim CommandBuild As MySqlCommandBuilder
                Dim myDataTable as new datatable
                Dim myConnString = "Server=larlar;" & _
                "Database=larlar;" & _
                "Uid=larlar;" & _
                "Pwd=larlar;" & _
                "Connect Timeout=30;"
                Dim myConnection As New MySqlConnection(myConnString)

    any ideas ?

    thx

  2. #2

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    12

    Re: how do u Insert Datatable to Mysql server ?

    sorry not sure why it posted twice, when i went to submit it said i needed to log in and i loged in and it submited twice.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    12

    Re: how do u Insert Datatable to Mysql server ?

    i have beed googling alittle and i have written this up hoping it will work but i seam to get a error at

    inscmd.Connection = myConnection

    saying

    Error 32 Value of type 'MySql.Data.MySqlClient.MySqlConnection' cannot be converted to 'System.Data.SqlClient.SqlConnection'

    can any one help ?

    Code:
            Dim myConnString = ";" & _
                "Database=cryisguid;" & _
                "Uid=;" & _
                "Pwd=;" & _
                "Connect Timeout=30;"
            Dim myConnection As New MySqlConnection(myConnString)
            Dim sqlcom As MySqlCommand = New MySqlCommand()
            Dim mySqlDataAdapter As MySqlDataAdapter
            Dim inscmd As New SqlCommand
    
            myConnection.Open()
            inscmd.Connection = myConnection
            Dim sqlda As New SqlDataAdapter
            inscmd.Parameters.Add("@name", SqlDbType.NVarChar, 28, "name")
            inscmd.Parameters.Add("guid", SqlDbType.NVarChar, 8, "guid")
            sqlda.InsertCommand = inscmd
            inscmd.CommandText = "INSERT INTO guids2(name,guid) VALUES(@name,@guid)"
            inscmd.ExecuteNonQuery() 
            sqlda.Update(InsertTable)
            myConnection.Close()

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    12

    Re: how do u Insert Datatable to Mysql server ?

    Took me way too long, but i finally got it, posting for all the people googling have having the same issues at me. thx for all the help people.



    Code:
     Dim myConnString = "Server=;" & _
        "Database=;" & _
        "Uid=;" & _
        "Pwd=;" & _
        "Connect Timeout=30;"
            Dim myConnection As New MySqlConnection(myConnString)
            Dim workParam As MySqlParameter
            Dim mySqlDataAdapter As New MySqlDataAdapter
            Dim mySqlcb As MySqlCommandBuilder
            Dim DataSetds As New DataSet()
            DataSetds.Tables.Add(InsertTable)
            myConnection.Open()
            mySqlcb = New MySqlCommandBuilder(mySqlDataAdapter)
            'SqlDataAdapter.InsertCommand = mySqlcb.GetInsertCommand
            mySqlcb.ReturnGeneratedIdentifiers = False
    
            mySqlDataAdapter.InsertCommand = New MySqlCommand("Insert into guids2 (name, guid) VALUES (?name, ?guid)", myConnection)
            workParam = mySqlDataAdapter.InsertCommand.Parameters.Add("?name", MySqlDbType.VarChar, 26)
            workParam.SourceVersion = DataRowVersion.Current
            workParam.SourceColumn = "name"
    
            workParam = mySqlDataAdapter.InsertCommand.Parameters.Add("?guid", MySqlDbType.VarChar, 8)
            workParam.SourceVersion = DataRowVersion.Current
            workParam.SourceColumn = "guid"
            mySqlDataAdapter.Update(DataSetds.Tables(0))
            'mySqlDataAdapter.Update(InsertTable)
            myConnection.Close()

Posting Permissions

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



Click Here to Expand Forum to Full Width