Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
176 views
in Technique[技术] by (71.8m points)

vb.net - Updating datagridview with mysql

My update textbox is named: updateref and my data field I am trying to update with the selected column is refid

I am sorry I am a noob and all new to integrating mysql with vb.net, any help would be appreciated! Thank you!

'MYSQL CODE

    Dim con As MySqlConnection = New MySqlConnection("my info")
    Dim reader As MySqlDataReader

    Try
        con.Open()
        Dim query As String
        Dim command As MySqlCommand
        query = "UPDATE exploitsociety SET reffer='" + updateref.Text + "' WHERE reffer='" + DataGridView1.CurrentCell.Selected + "';"
        command = New MySqlCommand(query, con)
        reader = command.ExecuteReader

        Catch ex As MySqlException
        MessageBox.Show(ex.Message)
    Finally
        con.Dispose()
        End try
        con.Close()

Basially I was wanting to just edit the column data in the dataviewgrid then just hit update but it was to complicated so I added a textbox to see if I could do it that way and I couldn't either.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It seems you try update query

Dim con As MySqlConnection = New MySqlConnection("my info")
Dim reader As MySqlDataReader

Try
    con.Open()
    Dim query As String


     Dim command As MySqlCommand
        query = "UPDATE exploitsociety SET reffer='" + updateref.Text + "' WHERE reffer='" + DataGridView1.CurrentCell.Selected + "';"
        command = New MySqlCommand(query, con)
  //      reader = command.ExecuteReader

  //     you need to run ExecuteNonQuery instead of ExecuteReader
      int UpdatedRows=  command.ExecuteNonQuery();

        Catch ex As MySqlException
        MessageBox.Show(ex.Message)
    Finally
        con.Dispose()
        End try
    con.Close()

Just for your informationn

ExecuteReader

Execute Reader will be used to return the set of rows, on execution of SQL Query or Stored procedure using command object. This one is forward only retrieval of records and it is used to read the table values from first to last.(Read More about ExecuteReader)

ExecuteNonQuery

ExecuteNonQuery method will return number of rows effected with INSERT, DELETE or UPDATE operations. This ExecuteNonQuery method will be used only for insert, update and delete, Create, and SET statements. (Read More about ExecuteNonQuery)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...