你能帮忙吗,如果我要你帮忙(DATASET,我只是不太了解) [英] would you help, If I ask you help (DATASET, I just don't know it well)

查看:66
本文介绍了你能帮忙吗,如果我要你帮忙(DATASET,我只是不太了解)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.
我是数据集的新手,对此不太了解.
请告诉我为什么我得到对象引用未设置为对象的实例".运行时错误在这里.
在包含"HOSEIN"的行中引发了我的错误.
谢谢!

Hello everybody.
I am new to dataset and don''t know it very well.
Please tell me why I got an "Object reference not set to an instance of an object." runtime error here.
My error is raised in the line that has "HOSEIN".
Thank you!

string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\db1.mdb";
using (OleDbConnection myConnection = new OleDbConnection(ConnectionString)) // create connection to connect to DB
{
    OleDbDataAdapter myAdapter = new OleDbDataAdapter(); // create a adapter for the table
    myAdapter.TableMappings.Add("TAbLE", "Students");

    myConnection.Open();
    MessageBox.Show("connection is open");

    OleDbCommand myCommand = new OleDbCommand("SELECT * FROM Students", myConnection);
    myCommand.CommandType = System.Data.CommandType.Text;

    // set the adapter select command
    myAdapter.SelectCommand = myCommand;

    OleDbCommand myUpdateCommand = new OleDbCommand("Update Students SET StudentName=@StudentName, Description=@Description WHERE ClassNumber=@ClassNumber AND Place=@Place");
    myUpdateCommand.CommandType = CommandType.Text;

    //fill the DataSet
    DataSet myDataSet = new DataSet("MyFirstDataSet");

    myAdapter.Fill(myDataSet);

    myDataSet.Tables["Students"].Rows[0]["StudentName"] = "HOSEIN";
    myAdapter.Update(myDataSet);
    myConnection.Close();
    MessageBox.Show("connection is closed");

推荐答案

我猜测myDataSet为null或其中没有名为"Students"的表.

这行代码不应该将数据库表映射到您的数据集:

I''m guessing that either myDataSet is null or it doesn''t have a table called "Students" in it.

Shouldn''t this line map a DB table to your dataset:

myAdapter.TableMappings.Add("TAbLE", "Students");



在这种情况下,我将其更改为:



in which case I''d change it to this:

myAdapter.TableMappings.Add("Students", "Students");



如果这样做没有帮助,请在该行上设置一个断点:



if that doesn''t help, set a breakpoint on the line:

myDataSet.Tables["Students"].Rows[0]["StudentName"] = "HOSEIN";



并查看myDataSet对象包含的内容.



and have a look at what the myDataSet object contains.


感谢您的建议,我更改了您告诉我的方式
但是运行时错误仍然存​​在
我试图在其中建立一个断点,然后深入研究DataSet
实际上我已经在数据集中找到了我的数据库数据
我发现这与您提到的Table的名称有关
但说实话我实际上不理解DataSet的概念
如果有人告诉我一个我能很好理解的参考文献,我会很感激,我的意思是很好的例证,很多谷歌搜索对我来说不是有效的
再次感谢
Thanks for your suggestion ,I changed the way you told me
but the run time error still exists
and I tried to have a breakpoint in there and I go deep in the DataSet
and actually I have found my DataBase Data in the DataSet
and I found that It was about the name of Table that you mentioned
but to be honest I actually don''t understand the concept of DataSet
Would be thankful if someone tell me about a reference that I can understand it well, a good illustration I mean, lots of googling wasn''t efficient for me
thanks again


这篇关于你能帮忙吗,如果我要你帮忙(DATASET,我只是不太了解)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆