0

this is my select query, i was able to retrieve in a textbox. but when i updating, it updates all of its record in first column and i know that the reason is the 'ExecuteScalar', so anyone knows what should i replace in this? because i only want to update first row in a column?

Dim fname As New SqlCommand 
Dim lname As New SqlCommand

Dim CMD As New SqlCommand

con = New SqlConnection("server=;uid=admin;pwd=t;database=")
con.Open()

fname = New SqlCommand("select first_name from employee_info where employee_id='" & TextBox1.Text & "';", con)

lname = New SqlCommand("select last_name from employee_info where employee_id='" & TextBox1.Text & "';", con)

CMD.Connection = con

TextBox3.Text = fname.ExecuteScalar

fname.ExecuteNonQuery()

TextBox4.Text = lname.ExecuteScalar

lname.ExecuteNonQuery()

by the way this is my update query....

  fname = New SqlCommand("UPDATE employee_info SET first_name= '" & TextBox3.Text & "';", con)
        fname.Connection = con
        fname.ExecuteNonQuery()

 lname = New SqlCommand("UPDATE employee_info SET last_name= '" & TextBox4.Text & "';", con)
        lname.Connection = con
        lname.ExecuteNonQuery()
Jade
  • 2,972
  • 1
  • 11
  • 9
  • I hate to sound like a broken record but look into using parameters in your queries. This way you learn early on the right way to query your data.. http://stackoverflow.com/questions/542510/how-do-i-create-a-parameterized-sql-query-why-should-i – Jason Bayldon Feb 26 '14 at 02:55

1 Answers1

2

Because you didn't specify which row you want to update. For example;-

fname = New SqlCommand("UPDATE employee_info SET first_name= '" & TextBox3.Text & "' WHERE [columnName]= '[columnValue]'", con) 
fname.Connection = con fname.ExecuteNonQuery()
Hafiz Abdullah
  • 248
  • 1
  • 5
  • 14