Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...