这是我的选择查询,我能够在文本框中检索。但是当我更新时,它更新了第一列中的所有记录,我知道原因是'ExecuteScalar',所以任何人都知道我应该在这里替换什么?因为我只想更新一列中的第一行?
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()
顺便说一下,这是我的更新查询....
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()
答案 0 :(得分:2)
因为您没有指定要更新的行。例如; -
fname = New SqlCommand("UPDATE employee_info SET first_name= '" & TextBox3.Text & "' WHERE [columnName]= '[columnValue]'", con)
fname.Connection = con fname.ExecuteNonQuery()