sql不在c#中工作,但在sql中工作
第二部分已满,但第一部分不起作用。。有人能帮我吗:(我花了好几个小时看这个问题。)我还在学习:(既然你没有详细说明“不工作”的确切含义,我可以提出以下建议来解决你的问题,以便你能找到问题所在吗sql不在c#中工作,但在sql中工作,c#,C#,第二部分已满,但第一部分不起作用。。有人能帮我吗:(我花了好几个小时看这个问题。)我还在学习:(既然你没有详细说明“不工作”的确切含义,我可以提出以下建议来解决你的问题,以便你能找到问题所在吗 让您的查询在代码之外工作,即使用VS或SQL管理控制台中的查询工具(例如,只需测试更新节集status='Not Full',WHERE…。注意,您需要硬编码参数以确保查询实际工作 将工作查询转换为参数化查询(例如,更新节SET status=@status WHERE…。(参见下面的示例) 使用在IDE
string not = "Not full";
string str8 = "update section set status = '" + not + "' where ((select * from (select count(enrollstudent.section_id) from enrollstudent inner join section on section.id = enrollstudent.section_id && enrollstudent.section_id ='" + lblSection.Text + "' )as tbltmp1) != (select * from(select DISTINCT(sec_limit) from section inner join enrollstudent on enrollstudent.section_id = section.id where section.id = '" + lblSection.Text + "')as tbltmp2)) && id = '" + lblSection.Text + "'";
conn.Close();
conn.Open();
cmd = conn.CreateCommand();
cmd.CommandText = str8;
cmd.ExecuteNonQuery();
conn.Close();
string full = "Full";
string str5 = "update section set status = '" + full + "' where ((select * from (select count(enrollstudent.section_id) from enrollstudent inner join section on section.id = enrollstudent.section_id && enrollstudent.section_id ='" + lblSection.Text + "' )as tbltmp1) = (select * from(select DISTINCT(sec_limit) from section inner join enrollstudent on enrollstudent.section_id = section.id where section.id = '" + lblSection.Text + "')as tbltmp2)) && id = '" + lblSection.Text + "'";
conn.Close();
conn.Open();
cmd = conn.CreateCommand();
cmd.CommandText = str5;
cmd.ExecuteNonQuery();
conn.Close();
请详细说明“不工作”。您会遇到什么错误?而且,这几乎肯定是因为
lblSection
输入了无效的值。我建议使用google
来学习如何构造参数化的查询。。还可以使用调试器
我没有收到任何错误。。这只是在我更新状态时当我在sql中使用它们时,它将工作..就像我将LBL部分替换为5..与另一个相同..但是在查询中只有第一个不会更新
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand command = new SqlCommand(
"UPDATE section SET status = @Status WHERE ...", connection))
{
command.Parameters.Add(new SqlParameter("Status", status));
command.ExecuteNonQuery();
}
}