我又回來了。 我之前曾問過一個類似的問題,但即使在前一個anwser的幫助下,並用questionmarks嘗試它,而不是添加我嘗試過AddWithValue,我沒有任何運氣。SQL ASP.NET INSERT麻煩(第2部分)
我試圖將txt_Naam更改爲txt_Naam.Text,什麼都沒有。
同時把[]圍繞在列名上,沒有運氣。 它不斷給我這個「INSERT INTO語句中的語法錯誤。」。
這次我沒有得到下面的代碼。 可能是小事,但我無法弄清楚。 (再次...)
protected void btn_final_Click(object sender, EventArgs e)
{
string fact_adres = txt_Naam.Text + "," + txt_Anaam.Text + "," + txt_Adres.Text + "," + txt_Toevoeg.Text + "," + txt_Pcode.Text + "," + txt_Plaats.Text + "," + txt_Email.Text ;
string fact_adres1 = txt_Naam1.Text + "," + txt_Anaam1.Text + "," + txt_Adres1.Text + "," + txt_Toevoeg1.Text + "," + txt_Pcode1.Text + "," + txt_Plaats1.Text + "," + txt_Email1.Text;
string a = "1";
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; "
+ "Data Source=|DataDirectory|webwinkel.accdb";
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandText = "INSERT INTO Order (factuur_adres_id, verzend_adres_id, totaalprijs) VALUES (?, ?, ?);";
cmd.Parameters.Add("@factuur_adres", OleDbType.VarChar, 125).Value = fact_adres;
cmd.Parameters.Add("@verzend_adres", OleDbType.VarChar, 125).Value = fact_adres1;
cmd.Parameters.Add("@totaal_prijs", OleDbType.VarChar, 7).Value = a;
try
{
conn.Open();
OleDbDataReader reader = cmd.ExecuteReader();
reader.Close();
}
catch (Exception exc)
{
Label1.Text = exc.Message;
}
finally
{
conn.Close();
Session["Winkelwagen"] = null;
}
}
我試過了,它仍然給我錯誤。這就是爲什麼我將它改爲questionmarks。 – 2012-07-18 21:03:38
@ Big.S你現在得到了什麼錯誤? – 2012-07-18 21:04:21
@ Big.S在你的sql服務器上運行上面的查詢並檢查它是否在那裏工作?語法是正確的。 – 2012-07-18 21:08:44