2010-06-17 152 views
0
conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\\database.mdb"); 
conn.Open(); 

com = new OleDbCommand(@"insert into group 
          (groupid,groupname,nature,effect) 
         values 
          (@groupid,@groupname,@nature,@effect)", conn); 
com.Parameters.AddWithValue("@groupid", intialtxt); 
com.Parameters.AddWithValue("@groupname", groupnametxt); 
com.Parameters.AddWithValue("@nature", groupnaturecombo); 
com.Parameters.AddWithValue("@effect", efectivegroupcombo); 
com.ExecuteNonQuery(); 

conn.Close() 

我有寫這一點,但我得到的INSERT一個錯誤的語法錯誤的語句 請幫助我的人。語法錯誤INSERT INTO語句中

+1

@Kevin **謝謝!!!! ** – 2010-06-17 21:17:36

+0

我盡我所能:) – kemiller2002 2010-06-17 21:27:40

回答

0

的OleDbCommand(@「插入組(

你有一些錯別字:

  • 應該有表名和打開的括號之間的空間,就像這樣:group (groupid
+0

字符串之前的@很好。它允許C#中的多線字符串,並且不需要轉義空間字符。用於正則表達式和sql查詢非常方便。即:string pattern = @「\ d +」;而不是字符串模式=「\\ d +」; – 2010-06-17 21:23:40

+0

「@」實際上是有效的,它會指示字符串忽略轉義碼。例如,它可讓您將字符串「\」放入字符串中,而不是強制您使用「\\」的轉義碼。 – 2010-06-17 21:24:06

+0

Schla擊敗了我! – 2010-06-17 21:24:25

2

瘋狂的猜測,但嘗試鍵入[g羣]而不是隻有組。我假設由於「GROUP BY」子句,組字被保留。

1

Ahhh MS Access與你極其愚蠢的命名限制,允許表名中的空格允許使用SQL關鍵字的字段名稱。

GROUP是SQL reserved word。如果您有機會,我強烈建議您重命名它。也就是說,如果您不能重命名它,請在查詢[group]中用方括號括起來。

+0

非常感謝您的幫助。這是工作 – 2010-06-17 21:44:14

相關問題