![]() |
#2
hebingbing2008-05-09 17:08
不管程序有没有错误,首先感觉你的程序写的太……
//conn = DB.DBconntion(); //conn.Open(); string sql = "select top 8 * from news where type='IT业界'"; DB dt = new DB(); // conn.Close(); 我想这里的conn是不必要的吧?你用到conn了吗? DataList1.DataSource=dt.DBtable(sql).Tables[0].DefaultView; DataList1.DataBind(); //conn = DB.DBconntion(); //conn.Open(); string sql1 = "selecttop 8 * from news where type='PS专区'"; // DB dt1 = new DB(); //conn.Close(); DataList2.DataSource = dt.DBtable(sql1).Tables[0].DefaultView; DataList2.DataBind(); // conn = DB.DBconntion(); //conn.Open(); string sql2 = "select top 8 * from news where type='硬件天下'"; // DB dt2 = new DB(); // conn.Close(); DataList3.DataSource = dt.DBtable(sql2).Tables[0].DefaultView; DataList3.DataBind(); //conn = DB.DBconntion(); //conn.Open(); string sql3 = "select top 8 * from news where type='FLASH专区'"; // DB dt3 = new DB(); // conn.Close(); DataList4.DataSource = dt.DBtable(sql3).Tables[0].DefaultView; DataList4.DataBind(); |
我做了个自定义控件里面有多个datalist需要数据绑定
我是这样写的可是出现了错误
public partial class Controllers_first : System.Web.UI.UserControl
{
OleDbConnection conn;
protected void Page_Load(object sender, EventArgs e)
{
conn = DB.DBconntion();
conn.Open();
string sql = "select top 8 * from news where type='IT业界'";
DB dt = new DB();
conn.Close();
DataList1.DataSource=dt.DBtable(sql).Tables[0].DefaultView;
DataList1.DataBind();
conn = DB.DBconntion();
conn.Open();
string sql1 = "selecttop 8 * from news where type='PS专区'";
DB dt1 = new DB();
conn.Close();
DataList2.DataSource = dt1.DBtable(sql1).Tables[0].DefaultView;
DataList2.DataBind();
conn = DB.DBconntion();
conn.Open();
string sql2 = "select top 8 * from news where type='硬件天下'";
DB dt2 = new DB();
conn.Close();
DataList3.DataSource = dt2.DBtable(sql2).Tables[0].DefaultView;
DataList3.DataBind();
conn = DB.DBconntion();
conn.Open();
string sql3 = "select top 8 * from news where type='FLASH专区'";
DB dt3 = new DB();
conn.Close();
DataList4.DataSource = dt3.DBtable(sql3).Tables[0].DefaultView;
DataList4.DataBind();
我想可能是sql语句不能这样重复出现吧
错误::
无效的 SQL语句;期待 'DELETE'、'INSERT'、'PROCEDURE'、'SELECT'、或 'UPDATE'。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Data.OleDb.OleDbException: 无效的 SQL语句;期待 'DELETE'、'INSERT'、'PROCEDURE'、'SELECT'、或 'UPDATE'。
要怎么写呢?