总出现“添加失败未将对象引用设置到对象的实例”的提示,请大家帮忙指点一下!
private void button2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "" && textBox2.Text == "" && textBox3.Text == "" && textBox4.Text == "" && textBox5.Text == "" && textBox6.Text == "" && textBox7.Text == "" && textBox8.Text == "" && textBox9.Text == "")
            {
                MessageBox.Show("内容有为空的项","提示");
            }
                try
                {
                    string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=mingdan.mdb";  //相对路径。tongxunlu.mdb存放于当前目录下,即debug文件夹下       
                    OleDbConnection conn = new OleDbConnection(strConnection);
                    OleDbDataAdapter thisAdapter = new OleDbDataAdapter("select *from tongxunlu", conn);
                    OleDbCommandBuilder thisBuilder = new OleDbCommandBuilder(thisAdapter);        //看似没有用,但却不可缺少。它可以根据指定的sql语句来完成 添加,删除,修改等操作 
                    DataSet thisDataSet = new DataSet();
                    thisAdapter.Fill(thisDataSet, "mingdan");
                    DataRow thisRow = thisDataSet.Tables["tongxunlu"].NewRow();
                    thisRow["name"] = textBox1.Text.Trim();
                    thisRow["sex"] = textBox2.Text.Trim();
                    thisRow["age"] = textBox3.Text.Trim();
                    thisRow["adgree"] = textBox4.Text.Trim();
                    thisRow["address"] = textBox5.Text.Trim();
                    thisRow["addnumber"] = textBox6.Text.Trim();
                    thisRow["E-mail"] = textBox7.Text.Trim();
                    thisRow["QQ"] = textBox8.Text.Trim();
                    thisRow["tel"] = textBox9.Text.Trim();
                    thisDataSet.Tables["tongxunlu"].Rows.Add(thisRow);
                    thisAdapter.Update(thisDataSet, "tongxunlu");
                    conn.Close();                    MessageBox.Show("添加成功", "提示");                    textBox1.Text = "";
                    textBox2.Text = "";
                    textBox3.Text = "";
                    textBox4.Text = "";
                    textBox5.Text = "";
                    textBox6.Text = "";
                    textBox7.Text = "";
                    textBox8.Text = "";
                    textBox9.Text = "";
                }
                catch (Exception ex)
                {
                    MessageBox.Show("添加失败" + ex.Message, "提示");
 
                }         }   

解决方案 »

  1.   

    select *from tongxunlu
    --
    select * from tongxunl加个空格
      

  2.   

    那个select *from tongxunlu是手误吧,select * from tongxunluthisAdapter.Fill(thisDataSet, "mingdan"); //dataset你取别名
      DataRow thisRow = thisDataSet.Tables["mingdan"].NewRow(); //数据集中你也要用别名mingdan
      

  3.   

    这里应该是这样的
         thisAdapter.Fill(thisDataSet,'"tongxunlu");
        DataRow thisRow = thisDataSet.Tables["tongxunlu"].NewRow(); 
    确实手误,但是改正之后又有新的错误提示“添加失败INSERT INTO语句的语法错误”