请大家帮我看一下,我段代码为什么错,又何改正,谢谢

Peiyangjun_Pyj 2003-02-27 04:48:10

string CONNECTIONSTRING="uid=sa;pwd=sa;server=MyServer;database=pubs;"://正确
string strSql="select * from authors";//正确
SqlConnection connWorking = new SqlConnection(CONNECTIONSTRING);
SqlDataAdapter daWorking = new SqlDataAdapter(strSql,connWorking);
SqlCommandBuilder cbWorking = new SqlCommandBuilder(daWorking);


try
{
// Open a connection to the database
connWorking.Open();
// Call the update method on the dataset, this will
// make the appropriate insert, updates and deletes
//为什么会在下面出错!请帮忙,谢谢!
daAuthors.DeleteCommand = cbWorking.GetDeleteCommand();
daAuthors.InsertCommand = cbWorking.GetInsertCommand();
daAuthors.UpdateCommand = cbWorking.GetUpdateCommand();
}
catch(Exception ee)
{
return false;
}
...全文
43 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
lbx1979 2003-02-27
  • 打赏
  • 举报
回复
daAuthors没定义??
Peiyangjun_Pyj 2003-02-27
  • 打赏
  • 举报
回复
daAuthors.DeleteCommand = cbWorking.GetDeleteCommand();.
///错误提示如下:是用的:ASP.net应用程序!:

“/WebApplication4”应用程序中的服务器错误。
--------------------------------------------------------------------------------

未将对象引用设置到对象的实例。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。

异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。

源错误:


行 98: // Call the update method on the dataset, this will
行 99: // make the appropriate insert, updates and deletes
行 100: daAuthors.DeleteCommand = cbWorking.GetDeleteCommand();
行 101: daAuthors.InsertCommand = cbWorking.GetInsertCommand();
行 102: daAuthors.UpdateCommand = cbWorking.GetUpdateCommand();


源文件: d:\inetpub\wwwroot\webapplication4\dataaccess.cs 行: 100
visualpony 2003-02-27
  • 打赏
  • 举报
回复
抱什么错
ArEoN 2003-02-27
  • 打赏
  • 举报
回复
打开一个连接后要关闭

111,119

社区成员

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

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

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