簡體   English   中英

保存具有多個表的數據集

[英]Saving a dataset with multiple tables

對於我正在從事的項目,我正在使用Access數據庫,該數據庫是從服務器下載來存儲數據的。 下載文件后,我打開數據庫並將其復制到數據集中,以使編輯數據更加容易。

我現在遇到的問題是我需要將數據集保存回訪問數據庫,但是在程序執行期間,我也向數據集添加了新列,所以有一種方法可以更新存儲在數據庫中的訪問數據庫。用新數據和新列下載后的E:\\驅動器,還是我必須從頭開始創建新數據庫。

我用來加載和復制數據集的代碼

private void accessConnect()
    {
        //Assign values to access database variables 
        Connection = new OleDbConnection();
        command = new OleDbCommand();
        adapter = new OleDbDataAdapter();
        databaseDataSet = new DataSet();

        //Assign location of database to connection variable 
        connection.ConnectionString =
            @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\EAttendance.accdb;" +
            "Persist Security Info=False";

        //Establish connection with database
        command.Connection = connection;

        //Copy all tables into a c# dataset 
        try
        {
            //Select the user table in the database
            command.CommandText = "SELECT * FROM users";
            adapter.SelectCommand = command;

            //Copy table into dataset 
            adapter.Fill(databaseDataSet,"users");

            //Select the students table in the database
            command.CommandText = "SELECT * FROM students";
            adapter.SelectCommand = command;

            //copy the students database into the dataset 
            adapter.Fill(databaseDataSet, "students");

        }

        //catch exception and display error if application fails to read database 
        catch (OleDbException)
        {
            //Display error in form title bar
            this.Text = "Error #102 : Database Read Error";

            // Set connection value to false
            connectionBoolean = false; 

        }



    }

您錯過的是SQLDataReader

public SQLDataReader someReader
{
 get {return this.Reader("students");}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM