當我運行這段代碼erorr apeared關鍵字附近 不正確的語法,其中c#錯誤的語法附近的關鍵字在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 = " [email protected]_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 [email protected]";
ParsList.Add(new SqlParameter("@ID", D));
}
if (S_Aname.Text != "")
{
if (Cond != "")
Cond += " and ";
Cond += " Aname [email protected]";
ParsList.Add(new SqlParameter("@Aname", S_Aname.Text));
}
if (S_Ename.Text != "")
{
if (Cond != "")
Cond += " and ";
Cond += " Ename [email protected]";
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();
}
向我們展示由SelectStatement + Cond所做的最終查詢 – Adil
第二個代碼是最終查詢提出的b y select + cond –
你能得到你調試的查詢,並向我們展示查詢構造了什麼。 – Adil