C#更新数据库数据,sql错了吗?不报错但更新不了数据
代码如下:privatevoidlinkLabel2_LinkClicked(objectsender,LinkLabelLinkClickedEventArgse){s...
代码如下:
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string database = "Server=.;Database=WDLE;User='sa';Password='chd'";
SqlConnection connection = new SqlConnection(database);
string sql = "update mydo_job set status = 5 where job_id = '" + label2.Text + "';";
connection.Open();
SqlDataAdapter DataAdapter = new SqlDataAdapter(sql, connection);
DataSet ds = new DataSet();
DataAdapter.Fill(ds);
} 展开
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string database = "Server=.;Database=WDLE;User='sa';Password='chd'";
SqlConnection connection = new SqlConnection(database);
string sql = "update mydo_job set status = 5 where job_id = '" + label2.Text + "';";
connection.Open();
SqlDataAdapter DataAdapter = new SqlDataAdapter(sql, connection);
DataSet ds = new DataSet();
DataAdapter.Fill(ds);
} 展开
1个回答
展开全部
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string database = "Server=.;Database=WDLE;User='sa';Password='chd'";
SqlConnection connection = new SqlConnection(database);
string sql = "update mydo_job set status = 5 where job_id = '" + label2.Text + "';";
connection.Open();
SqlCommand cmd = new SqlCommand(sql, connection);
cmd.ExecuteNonQuery();
}
更多追问追答
追问
追答
那就是你的sql字符串拼接有问题了,你MessageBox.Show(sql);出来看下语句是怎样的嘛。
string sql = string.Format("update mydo_job set status = 5 where job_id = '{0}'",label2.Text)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询