当单击搜索按钮时,它给了我这个错误('43'附近的语法不正确)43是区域ID,我确保所有表中的区域ID都相同并且政府ID也相同,这是我使用的代码
protected void Button1_Click(object sender, EventArgs e)
{
//Page.RegisterStartupScript("open", "<script language=javascript>alert('dd')</script>");
// Session["conection"] = "Data Source=MEDICONSULT;Initial Catalog=test;Integrated Security=True";
Session["conection"] = "Data Source=MEDICONSULT;Initial Catalog=test1;Integrated Security=True";
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString);
connection.Open();
SqlCommand command = new SqlCommand();
connection = new SqlConnection((string) Session["conection"]);
connection.Open();
SqlDataAdapter da_1 = new SqlDataAdapter(command);
da_1 = new SqlDataAdapter();
command = new SqlCommand();
command.Connection = connection;
string sql1 = "select Address1,provname from sites where cat_id=2";
if (addressTextBox.Text != "")
{
sql1 = "SELECT provname,address1,LAT,LONG FROM site where cat_id=2 and provname like '%'+@provname+'%'";
SqlParameter search = new SqlParameter();
search.ParameterName = "@provname";
search.Value = addressTextBox.Text.Trim();
command.Parameters.Add(search);
}
if (DropDownList1.SelectedValue != "0")
{
sql1 = " SELECT area, address1, provname FROM sites WHERE cat_id=2 and gov_id='" + DropDownList1.SelectedValue + "'";
}
if (DropDownList2.SelectedValue != "0" && DropDownList1.SelectedValue != "0")
{
sql1 = "SELECT area, address1,provname FROM sites WHERE cat_id=2 and gov_id='" + DropDownList1.SelectedValue + "and area_id='" + DropDownList2.SelectedValue;
}
command.CommandText = sql1;
da_1.SelectCommand = command;
ds_1 = new DataSet();
da_1.Fill(ds_1, "sites");
searchResults.DataSource = ds_1;
searchResults.DataBind();
Label1.Text = ds_1.Tables[0].Rows.Count > 0 ? ds_1.Tables[0].Rows.Count.ToString() : "لا يوجد نتائج من البحث الذي ادخلته";
}