简体   繁体   English

c#关键字附近的语法不正确?

[英]incorrect syntax near the keyword where c#?

when i run the code this erorr apeared incorrect syntax near the keyword where c# 当我运行代码时,该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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM