-1
這是我的代碼,但我不能將數據插入到MS Access數據庫ASP.Net連接訪問
protected void Submit_Click(object sender, EventArgs e)
{
string connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;"
+ @"Data Source=E:\Parhai\Semester 06\Web\Assignments\i140097_Assignment_02\i140097_a02\i140097_a02\Database\Survey.mdb; Persist Security Info=False";
con = new OleDbConnection(connectionString);
con.Open();
using (con)
{
cmd = new OleDbCommand("INSERT INTO [Person] (Gender, Age, Occupation, Income) VALUES (" + gender.Text + ",'" + age.Text + ",'" + occup.Text + ",'" + income.Text + ")");
cmd.Parameters.AddWithValue("@Gender", gender.Text.ToString());
cmd.Parameters.AddWithValue("@Age", int.Parse(age.Text.ToString()));
cmd.Parameters.AddWithValue("@Occupation", occup.Text.ToString());
cmd.Parameters.AddWithValue("@Income", int.Parse(income.Text.ToString()));
lbl_show.Text = "Added!!!";
}
}
我認爲錯誤是由於ExecuteNonQuery ... 我應該添加它嗎? –
添加ExecuteNonQuerry給我一個例外... 怎麼辦???? –
根據您發佈的代碼,您從不執行SQL。然後你的評論提到了一個錯誤...你錯過了:cmd.ExecuteNonQuery(); –