×

Loading...
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。
Ad by
  • 最优利率和cashback可以申请特批,好信用好收入offer更好。请点链接扫码加微信咨询,Scotiabank -- Nick Zhang 6478812600。

@

看过来看过来,有人试过这几句吗? 谢谢! @@

1 string mySelectText = "SELECT * FROM Categories ORDER BY CategoryID";

2 string mySelectConn = "Data Source=localhost;Integrated
Security=SSPI;Initial Catalog=northwind";

3 SqlDataAdapter myDataAdapter = new
SqlDataAdapter(mySelectText,mySelectConn);

4 myDataAdapter.InsertCommand.CommandText = "INSERT INTO
Categories(CategoryName, Description, Picture)
Values(@CategoryName,@Description,@Picture)";

5 myDataAdapter.InsertCommand.Connection = (SqlConnection)
myDataAdapter.SelectCommand.Connection;


这五句话是从MSDN中copy过来的,运行到第四句时出错Error: Object reference not set to an instance of an object.
Report

Replies, comments and Discussions:

  • 工作学习 / IT杂谈 / 看过来看过来,有人试过这几句吗? 谢谢! @@
    1 string mySelectText = "SELECT * FROM Categories ORDER BY CategoryID";

    2 string mySelectConn = "Data Source=localhost;Integrated
    Security=SSPI;Initial Catalog=northwind";

    3 SqlDataAdapter myDataAdapter = new
    SqlDataAdapter(mySelectText,mySelectConn);

    4 myDataAdapter.InsertCommand.CommandText = "INSERT INTO
    Categories(CategoryName, Description, Picture)
    Values(@CategoryName,@Description,@Picture)";

    5 myDataAdapter.InsertCommand.Connection = (SqlConnection)
    myDataAdapter.SelectCommand.Connection;


    这五句话是从MSDN中copy过来的,运行到第四句时出错Error: Object reference not set to an instance of an object.
    • 嗯,小case啦。。。
      • ft. 你一天到晚改nickname, 刚才有个什么新地方新办公室的, 偶一看以为MM去相隔里拉了,兴奋地打个招呼, 居然是个在上海的家伙, 不知道是什么人, 7456~~~~~~~~~~~@@
        • 又有公司要去广州面试,一个月才给3000+ :( 说我要求高,还是现在薪水都那么少啊。。。
          • Good Luck.
            • 什么good luck,我还没想好去不去呢 :(:(:(
              • hehe, you can think it over now. @-@
              • 3000+ 你也要想想??这有什么好犹豫的??
                • 大哥,我学这老破玩意就是找不到工作的啊 :(
              • 考虑什么?别去!否则你就把海龟的台都坍尽了。我一个熟人在这里混不下去了才回的国内还拿7000/月
                • what kind of position?
          • 我觉得入门的薪水并不是最重要的。重要的是你是否喜欢那个工作和发展前景。
          • 没有工作经验的留学生,也就是3000多这个水平了。
    • 你想知道什么?
      • Did you have the same problem?
        • No. 不过我想知道你在问什么。你确认myDataAdapter创建成功了吗?
          • I'm just curious why MSDN code doesn't work. :-)
    • 在3后要加一句
      myDataAdapter.InsertCommand=new System.Data.SqlClient.SqlCommand();
      • Thanks. It should be ok after adding the new sqlcommand.
        But I still have problems to do update. :-(
        • what problem?
          • check ur email, pls. :-)