Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
添加从C#.net访问的记录_C#_Ms Access - Fatal编程技术网

添加从C#.net访问的记录

添加从C#.net访问的记录,c#,ms-access,C#,Ms Access,我对C#net一无所知。我在向连接的数据源(access文件)添加记录时遇到问题。编码为: int MaxRows = 0; int inc = 0; private void Form2_Load(object sender, EventArgs e) { con = new System.Data.OleDb.OleDbConnection(); ds1 = new DataSet(); con.Connec

我对C#net一无所知。我在向连接的数据源(access文件)添加记录时遇到问题。编码为:

    int MaxRows = 0;
    int inc = 0;

    private void Form2_Load(object sender, EventArgs e)
    {
        con = new System.Data.OleDb.OleDbConnection();
        ds1 = new DataSet();

        con.ConnectionString = " Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:/Documents and Settings/user/My Documents/anchu.accdb";
        string sql = "SELECT * From Table1";
        da = new System.Data.OleDb.OleDbDataAdapter(sql, con);

        con.Open();

        da.Fill(ds1, "Table1");
        NavigateRecords();

        con.Close();
        //con.Dispose();
    }
    private void NavigateRecords()
    {
        DataRow drow = ds1.Tables["Table1"].Rows[0];

        textBox1.Text = drow.ItemArray.GetValue(0).ToString();
        textBox2.Text = drow.ItemArray.GetValue(1).ToString();
        textBox3.Text = drow.ItemArray.GetValue(2).ToString();
        textBox4.Text = drow.ItemArray.GetValue(3).ToString();
    }


    private void groupBox1_Enter(object sender, EventArgs e)
    {

    }

    private void button2_Click(object sender, EventArgs e)
    {
        textBox1.Clear();
        textBox2.Clear();
        textBox3.Clear();
        textBox4.Clear();
    }

    private void button1_Click(object sender, EventArgs e)
    {
        System.Data.OleDb.OleDbCommandBuilder cb;
        cb = new System.Data.OleDb.OleDbCommandBuilder(da);

        DataRow drow = ds1.Tables["Table1"].NewRow();
        drow[1] = textBox1.Text();
        drow[2] = textBox2.Text();
        drow[3] = textBox3.Text();
        drow[4] = textBox4.Text();

        ds1.Tables["Table1"].Rows.Add(drow);

        MaxRows = MaxRows + 1;
        inc = MaxRows - 1;

        da.Update(ds1, "Table1");

        MessageBox.Show("Entry Added");
    }
}
我得到了8个相同类型的错误

非发票成员“System.Windows.Forms.Control.Text”不能像方法一样使用

错误示例

drow[1] = textBox1.Text();
取代

drow[1] = textBox1.Text;
属性不需要括号,文本是属性,而不是方法