本文介绍了你能帮忙吗,如果我要你帮忙(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");

推荐答案

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,我只是不太了解)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 03:37