关键字 C# 附近的语法不正确
本文关键字:语法 不正确 关键字 | 更新日期: 2023-09-27 18:32:11
当我运行代码时,这个 erorr 出现关键字 C# 附近的语法不正确
public SqlDataReader GetDR(CommandType HandelMode, string SQLStat, List<SqlParameter> Parms)
{
SqlDataReader R = null;
SqlCommand com = new SqlCommand();
SqlConnection Con = GetConn();
try
{
com.CommandText = SQLStat;
com.Connection = Con;
com.CommandType = HandelMode;
if (Parms != null)
{
foreach (SqlParameter P in Parms)
{
com.Parameters.Add(P);
}
}
R = com.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK);
return null;
}
finally
{
Con.Close();
}
return R;
}
private void pictureBox10_Click_2(object sender, EventArgs e)
{
List<SqlParameter> ParsList = new List<SqlParameter>();
string SelectStatement = "Select ID,Aname,Ename,I_D from " + ScreenMasterTableName;
string Cond = " ID_Co=@ID_Co";
ParsList.Add(new SqlParameter("@ID_Co", FormInfo.ID_Co));
if (S_ID.Text != "")
{
decimal D = 0;
decimal.TryParse(S_ID.Text, out D);
Cond += " and ID=@ID";
ParsList.Add(new SqlParameter("@ID", D));
}
if (S_Aname.Text != "")
{
if (Cond != "")
Cond += " and ";
Cond += " Aname =@Aname";
ParsList.Add(new SqlParameter("@Aname", S_Aname.Text));
}
if (S_Ename.Text != "")
{
if (Cond != "")
Cond += " and ";
Cond += " Ename =@Ename";
ParsList.Add(new SqlParameter("@Ename", S_Ename.Text));
}
if (Cond != "")
Cond = " where " + Cond;
var L = Bus.GetSearchedData(SelectStatement + Cond, ParsList);
dataGridView1.DataSource = L;
label9.Text = L.Count.ToString();
}
假设您的s_id已填写,您将有一个如下所示的查询:
where and ID=@ID