请大家帮忙看一下
总出现“添加失败未将对象引用设置到对象的实例”的提示,请大家帮忙指点一下!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["易做图"] = 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, "提示");
}
} --------------------编程问答-------------------- 名称空间都添加进来没有? --------------------编程问答-------------------- 显示是哪一行 出的异常? --------------------编程问答-------------------- select *from tongxunlu
--
select * from tongxunl加个空格 --------------------编程问答-------------------- 你调试一下啊 看下是那句出的问题.就好解决了 --------------------编程问答-------------------- 那个select *from tongxunlu是手误吧,select * from tongxunlu
thisAdapter.Fill(thisDataSet, "mingdan"); //dataset你取别名
DataRow thisRow = thisDataSet.Tables["mingdan"].NewRow(); //数据集中你也要用别名mingdan --------------------编程问答-------------------- 这里应该是这样的
thisAdapter.Fill(thisDataSet,'"tongxunlu");
DataRow thisRow = thisDataSet.Tables["tongxunlu"].NewRow();
确实手误,但是改正之后又有新的错误提示“添加失败INSERT INTO语句的语法错误”
--------------------编程问答-------------------- 对象没有实例化 --------------------编程问答--------------------
具体指点一下
补充:.NET技术 , C#