更新时间:2023-02-08 16:38:27
请阅读我对这个问题的评论。
看看这里:使用DataAdapters更新数据源 [ ^ ]
如果你想用sql更新数据声明,您应该使用更新 [ ^ ] statement。
SqlCommand cmd = new SqlCommand(更新示例,myConnection;
您的命令文本不完整。您究竟需要更新什么?你需要使用这样的命令文本SqlConnection myConnection = new SqlConnection(connectionString) ;
myConnection。打开();
SqlCommand cmd = new SqlCommand( UPDATE示例集
samplecode = + yourvalue,myConnection);
cmd.CommandType = CommandType。文字;
批量更新使用Sql Merge将对您有用
尝试使用它
upsert to sql [ ^ ]
合并Sql [ ^ ]
批量转发到sql server [ ^ ]
I have a grid view and an update button outside the grid view. When the user make some changes to the records inside the grid view,the records in the database will also be updated.
Here's my code:
protected void Button2_Click(object sender, EventArgs e)
{
string connectionString = "Server=192.168.100.252;Database=AMICASSA_Checklist;Trusted_Connection=true";
SqlConnection myConnection = new SqlConnection(connectionString);
myConnection.Open();
SqlCommand cmd = new SqlCommand("UPDATE Sample ", myConnection);
SqlDataReader red = cmd.ExecuteReader();
red.Close();
myConnection.Close();
BindData();
}
Can Anyone help me?
Please, read my comment to the question.
Have a look here: Updating Data Sources with DataAdapters[^]
If you would like to update data using sql statement, you should use UPDATE[^] statement.
SqlCommand cmd = new SqlCommand("UPDATE Sample ", myConnection);
Your command text is incomplete. What exactly you need to update? You need to use the command text something like thisSqlConnection myConnection = new SqlConnection(connectionString); myConnection.Open(); SqlCommand cmd = new SqlCommand("UPDATE Sample set samplecode="+yourvalue , myConnection); cmd.CommandType = CommandType.Text;
Bulk Update using Sql Merge will be useful for you
Try with it
upsert to sql[^]
Merge in Sql[^]
bulk upsert to sql server[^]