我真的是无语了,怎么回有错误呢?大虾帮帮忙!

acui9937 2003-07-19 09:38:36
系统说这里出了错:
myCommand.Fill(ds,"t_table");
到底是为什么呢?
string Table;
Table=Request.QueryString["Table"];
string SearchId,SearchTitle;
switch(Table)
{
case "t_links":
SearchId="link_id";
SearchTitle="link_title";
break;
case "t_info":
SearchId="info_id";
SearchTitle="info_title";
break;
}

//连接数据库
SqlConnection myConnection;
myConnection = new SqlConnection
("server=(local);database=graduate_student;user id=sa;password=sql");
SqlDataAdapter myCommand = new SqlDataAdapter
("select SearchId,SearchTitle from Table",myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds,"t_table");

MyDataGrid.DataSource=ds.Tables["t_table"].DefaultView;
MyDataGrid.DataBind();
...全文
52 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
zx_wang 2003-07-20
  • 打赏
  • 举报
回复
你的OLEDB有问题,这个问题我碰到过,你可以在MS的网站下载新的 MDAC2.7进行update
huhong81312 2003-07-19
  • 打赏
  • 举报
回复
错当然不会错不过SqlDataAdapter会自动管理SqlDataAdapter的连接的如果是SqlCommand就1定要先打开数据库连接。
mittee 2003-07-19
  • 打赏
  • 举报
回复
myConnection.Close()
myConnection.Open()
先关闭再打开永远不会出错!!!1
huhong81312 2003-07-19
  • 打赏
  • 举报
回复
哈哈。晕!什么myConnection.Open()啊SqlDataAdapter自动会打开SqlConnection的连接的,你的错误是MyDataGrid.DataSource=ds.Tables["t_links"].DefaultView;
你应该用下面的语句:
MyDataGridMy.SetDataBinding(ds,"t_links");
brightheroes 2003-07-19
  • 打赏
  • 举报
回复
在执行Command之前要打开数据库的连接,操作完毕之后关掉它
brightheroes 2003-07-19
  • 打赏
  • 举报
回复
myConnection.Open()
myConnection.Close()
acui9937 2003-07-19
  • 打赏
  • 举报
回复
他说我用了没有赋值得strSQL.
我想用最简单的来做试验,
结果还是出了错:
我的编码如下:
SqlConnection myConnection;
myConnection = new SqlConnection
("server=(local);database=graduate_student;user id=sa;password=sql");
SqlDataAdapter myCommand = new SqlDataAdapter
("select link_id,link_title from t_links",myConnection);
DataSet ds = new DataSet();
myCommand.Fill(ds,"t_links");
MyDataGrid.DataSource=ds.Tables["t_links"].DefaultView;
MyDataGrid.DataBind();
他说这个地方出了错:
MyDataGrid.DataSource=ds.Tables["t_links"].DefaultView;
请问:为什么?
panyee 2003-07-19
  • 打赏
  • 举报
回复
string strSQL = "select " + SearchId + "," + SearchTitle + " from " + Table;
SqlDataAdapter myCommand =
new SqlDataAdapter(strSQL,myConnection);
panyee 2003-07-19
  • 打赏
  • 举报
回复
select SearchId,SearchTitle from Table


你这个sql语句要动态生成 , 而不是直接这么写

111,093

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧