System.Data.SqlClient.SqlException:'a' 附近有语法错误.

System.Data.SqlClient.SqlException:'a' 附近有语法错误.
这个是程序:
public partial class DiscountWare :System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
if IsPostBack)
{
string connstr = ConfigurationManager.ConnectionStrings["SuperMarketConnectionString"].ConnectionString;
SqlConnection sqlConn = new SqlConnection(connstr);
sqlConn.Open();
string str = "select splb_TypeName from T_WareType";
SqlCommand cmd = new SqlCommand(str,sqlConn);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
DropDownList1.Items.Add(dr["splb_TypeName"].ToString());
}
GridView1.DataSourceID = "SqlDataSource1";
}
}
protected void Button1_Click(object sender,EventArgs e)
{
string connstr = ConfigurationManager.ConnectionStrings["SuperMarketConnectionString"].ConnectionString;
SqlConnection sqlConn = new SqlConnection(connstr);
sqlConn.Open();
string str = "SELECT sp_WareName,sp_AllSum,sp_SellSum,sp_Price,sp_Information,splb_TypeName";
str = str + "FROM T_Ware a JOIN T_WareType b ON a.splb_TypeID=b.splb_TypeID where";
str = str + "b.splb_TypeName=" + DropDownList1.SelectedValue.ToString().Trim() + "";
if (TextBox1.Text = "")
{
str = str + "and a.sp_WareName like" + "%" + TextBox1.Text.Trim() + "%";
}
this.GridView1.DataSourceID = null;
SqlDataSource1.SelectCommand = str;
GridView1.DataSourceID = "SqlDataSource1";
}
}
靓点ww 1年前 已收到1个回答 举报

要做幸福的小女人 幼苗

共回答了21个问题采纳率:95.2% 举报

sql字符串组合时请在结尾加空格个防止,不然会出现语法问题

1年前

6
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 0.044 s. - webmaster@yulucn.com