早教吧作业答案频道 -->其他-->
System.Data.SqlClient.SqlException:'a'附近有语法错误.这个是程序:publicpartialclassDiscountWare:System.Web.UI.Page{protectedvoidPageLoad(objectsender,EventArgse){ifIsPostBack){stringconnstr=ConfigurationManager.ConnectionStri
题目详情
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";
}
}
这个是程序:
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";
}
}
▼优质解答
答案和解析
sql字符串组合时请在结尾加空格个防止,不然会出现语法问题
看了 System.Data.Sq...的网友还看了以下:
未处理的“System.Data.OleDb.OleDbException”类型的异常出现在sys 2020-05-17 …
System.Data.SqlClient.SqlException:''附近有语法错误.stri 2020-05-17 …
system.data.sqlclient.sqlexception‘01’附近语法错误selec 2020-05-17 …
System.Data.SqlClient.SqlException:'a'附近有语法错误.这个是 2020-05-17 …
System.Data.SqlClient.SqlException有语法错误.想请问一下,为什么 2020-05-17 …
datalist实现分页出问题,publicpartialclassDefault2:System 2020-05-17 …
c#命名空间的问题、.我B项目里以前有个system.Data我在A项目里引用过,后来把那个文件改 2020-05-17 …
A Database Management System(DBMS) consists of a c 2020-05-26 …
method is the use of a data processing system to r 2020-05-26 …
解释下这段JS代码是什么意思啊privatevoidgrdGzlxbItemDataBound(ob 2020-11-01 …