我想在多个表中搜索关键字(在asp.net上写的),然后再repeater中显示, 我在网上看到是用union关键字 但我写到我后台就有错 但我5知道是哪里的问题,高手指教啊。下面是我写的代码:
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["information"].ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from ( select * from zhaoling union select * from main ) where [content] like @content or [title] like @title or [posstime] like @posstime";
cmd.Connection = con;
cmd.Parameters.Add(new SqlParameter("@content", "%" + TextBox1.Text + "%"));
cmd.Parameters.Add(new SqlParameter("@title", "%" + TextBox1.Text + "%"));
cmd.Parameters.Add(new SqlParameter("@posstime", "%" + TextBox1.Text + "%"));
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
Repeater1.DataSource = ds;
Repeater1.DataBind();
弹出的错误是:“/shiwuxitong”应用程序中的服务器错误。
--------------------------------------------------------------------------------在关键字 'where' 附近有语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 在关键字 'where' 附近有语法错误。源错误:
行 30: con.Open();
行 31: DataSet ds = new DataSet();
行 32: da.Fill(ds);
行 33: con.Close();
行 34: Repeater1.DataSource = ds;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["information"].ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "select * from ( select * from zhaoling union select * from main ) where [content] like @content or [title] like @title or [posstime] like @posstime";
cmd.Connection = con;
cmd.Parameters.Add(new SqlParameter("@content", "%" + TextBox1.Text + "%"));
cmd.Parameters.Add(new SqlParameter("@title", "%" + TextBox1.Text + "%"));
cmd.Parameters.Add(new SqlParameter("@posstime", "%" + TextBox1.Text + "%"));
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
Repeater1.DataSource = ds;
Repeater1.DataBind();
弹出的错误是:“/shiwuxitong”应用程序中的服务器错误。
--------------------------------------------------------------------------------在关键字 'where' 附近有语法错误。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Data.SqlClient.SqlException: 在关键字 'where' 附近有语法错误。源错误:
行 30: con.Open();
行 31: DataSet ds = new DataSet();
行 32: da.Fill(ds);
行 33: con.Close();
行 34: Repeater1.DataSource = ds;
解决方案 »
- datalist绑定fck里的值后 出现html标签 怎么解决?
- 这个小问题困扰了我一个晚上,现在终于发现,开发的注意了。
- 合并行 新手
- ASP代码(VBscript)中怎么调用activereports,给出具体代码
- 真没分了,一个Gridview简单问题
- 求一个好用的中文验证码控件?
- 未将对象引用到对象实例,提示用new
- 十万火急关于DropDownList的赋值
- 问下在datalist中使用checkbox的问题,有点急
- 自动生成试卷的代码怎么写?
- 奇怪了,GridView中TemplateField 中的按钮点过之后就重新RowCreated
- 对于Ajax post数据多的时候解决方法 有简洁的jquery方法post么
where附近有错···
where附近有错···
我用的是mysql5的,代码如下:
Imports System.Data
Imports System.Data.Odbc Partial Class _Default
因为你两个表数据结构不一样。使用 UNION、INTERSECT 或 EXCEPT 运算符合并的所有查询必须在其目标列表中有相同数目的表达式