[英]How to update particular record using update query in SQL Server with vb.net?
I have the query to retrieve selected record in textbox ./.. 我有查询以检索文本框./。中的选定记录。
How to use this query to update record : 如何使用此查询更新记录:
I want when I enter sumit in textbox1 and click submit button then the record with ID 1 will be updated to name sumit/// 我想在文本框1中输入sumit并单击“提交”按钮,然后将ID为1的记录更新为名称sumit ///
Dim SQLData As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
Dim cmdSelect As New System.Data.SqlClient.SqlCommand("SELECT TOP 1 Name FROM Table1 Order by Id DESC", SQLData)
SQLData.Open()
Dim dtrReader As System.Data.SqlClient.SqlDataReader = cmdSelect.ExecuteReader()
If dtrReader.HasRows Then
While dtrReader.Read()
TextBox1.Text = dtrReader("Name")
End While
Else
Response.Write("No customer found for the supplied ID.")
End If
dtrReader.Close()
SQLData.Close()
Build a SqlCommand with a CommmandText like this 用这样的CommmandText构建SqlCommand
UPDATE FOO SET CustomerName = @CustomerName WHERE ID = @ID
then add two parameters to your commmand with values capture from inputs and run it after setting connection and opening it. 然后将两个参数添加到命令中,并从输入中捕获值,并在设置连接并打开它后运行它。
Take a look at this page and it will help you through your work done 看看这个页面 ,它将帮助您完成工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.