我在這裏搜索了我的問題,但找不到它。我正在使用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