我在我的C#代碼SqlCommand的插入查詢
connexion = new SqlConnection(connexionString);
connexion.Open();
List<int> liste = client.GetIDFichiers(1210);
int a = 2;
foreach (int idfichier in liste)
{
a++;
using (connexion)
{
using (SqlCommand sqlCmd = new SqlCommand("INSERT INTO REL_Fab3DLotFichier_Fichier3D (IDREL_Fab3DLotFichier_Fichier3D,IDFichier3D,IDFab3DLotFichier,CreePar,CreeLe,ModifiePar,DateMaj,EstActif) VALUES (" + a + "," + idfichier + "," + 17965 + "," + null + "," + null + "," + null + "," + null + "," + 1 + ")", connexion))
{
try
{
sqlCmd.ExecuteNonQuery();
}
catch (Exception ex) { MessageBox.Show(ex.ToString()); }
}
}
}
插入工作不執行插入查詢,我不知道爲什麼。選擇和刪除查詢工作正常。只有當我嘗試插入值出現一個syntaxic錯誤。
- 什麼是語法錯誤?
- 我該如何解決?
請註明錯誤... – 2013-05-03 09:51:06
告訴你表模式 – 2013-05-03 09:52:26
哇我應該在哪裏開始!首先,您將字符串和空值連接起來。其次...考慮參數化查詢。 – 2013-05-03 09:53:48