-4
我得到錯誤「INCORRECT SYNTAX NEAR''
附近有語法錯誤'C#
這裏是我的代碼:。
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Mr\Documents\Student.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.Parameters.Clear();
cmd.CommandText = "insert into tblHesabdary(Shahriye Koll,Pardakhty,Mablagh,Naghdy - Shomare Fish,Albaghy,Name,Family)values(@SK,@P,@M,@NSF,@A,@N,@F)";
cmd.Parameters.AddWithValue("@SK", shahriye_KollTextBox.Text);
cmd.Parameters.AddWithValue("@P", pardakhtyTextBox.Text);
cmd.Parameters.AddWithValue("@M", mablaghTextBox.Text);
cmd.Parameters.AddWithValue("@NSF", naghdy___Shomare_FishTextBox.Text);
cmd.Parameters.AddWithValue("@A", albaghyTextBox.Text);
cmd.Parameters.AddWithValue("@N", nameTextBox.Text);
cmd.Parameters.AddWithValue("@F", familyTextBox.Text);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("jj");
我的數據庫是SQL Server Express的
不要在'Naghdy - Shomare Fish'中創建帶空格的列。您可以在查詢中始終使用別名,例如:'SELECT NaghdyShomareFish AS [Naghdy - Shomare Fish] FROM ...'。 – 2014-10-10 14:31:31