我在这里搜索了我的问题,但找不到它。我正在使用Microsoft VS 2010 C#。ExecuteNonQuery:连接属性尚未初始化
这里是我的代码:
private OleDbConnection myCon;
public Form5()
{
myCon = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|ForeignWorkerinfo.accdb");
InitializeComponent();
}
private void Form5_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'foreignWorkerinfoDataSet.FWinFO' table. You can move, or remove it, as needed.
this.fWinFOTableAdapter.Fill(this.foreignWorkerinfoDataSet.FWinFO);
}
private void button1_Click(object sender, EventArgs e)
{
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = myCon;
cmd = new OleDbCommand("INSERT INTO [FWinFO] ([ID], [Name], [Gender], [Date of Birth], [Country], [Date of Expire], [Passport No], [Working Place]) VALUES (?, ?, ?, ?, ?, ?, ?, ?);");
cmd.Parameters.AddWithValue("@id", textBox8.Text);
cmd.Parameters.AddWithValue("@name", textBox1.Text);
cmd.Parameters.AddWithValue("@gender", textBox2.Text);
cmd.Parameters.AddWithValue("@dob", dateTimePicker1.Value);
cmd.Parameters.AddWithValue("@country", textBox4.Text);
cmd.Parameters.AddWithValue("@doe", dateTimePicker2.Value);
cmd.Parameters.AddWithValue("@passport", textBox6.Text);
cmd.Parameters.AddWithValue("@workplace", textBox7.Text);
cmd.ExecuteNonQuery();
myCon.Close();
}
谁能告诉我,为什么连接属性尚未初始化?
您所看到的具体错误是什么?一个'try/catch'块会有帮助... – Brian 2013-03-06 16:53:34
它出来了同样的问题:( – 2013-03-07 04:49:48