我在我的查詢獲取SQL異常:SqlException''附近語法不正確
[SQLEXCEPTION(0x80131904):附近有語法錯誤 '?'。關鍵字「用戶」。]近不正確 語法
我在做什麼錯?這個例外是什麼意思?
protected void Submit_Click(object sender, EventArgs e)
{
string myConnection = @"Data Source=REDDEVIL;Initial..."
SqlConnection conn = new SqlConnection(myConnection);
HttpPostedFile postedFile = FileUpload1.PostedFile;
string fileName = Path.GetFileName(postedFile.FileName);
string fileExtension = Path.GetExtension(fileName);
if (fileExtension.ToLower() == ".jpg" || fileExtension.ToLower() == ".bmp" ||
fileExtension.ToLower() == ".gif" || fileExtension.ToLower() == ".png")
{
Stream stream = postedFile.InputStream;
BinaryReader binaryReader = new BinaryReader(stream);
byte[] bytes = binaryReader.ReadBytes((int)stream.Length);
string query2 = "INSERT INTO Manager (ID,Name,Address,Phone,Cell,Email,DOB,Commission,Comments,Photo,User ID,IsActive) VALUES (?ID,?Name,?Address,?Phone,?Cell,?Email,?DOB,?Commission,?Comments,?Photo,?User_ID,?IsActive)";
SqlCommand cmd2 = new SqlCommand(query2, conn);
cmd2.Parameters.AddWithValue("?ID", mgrID.Text);
cmd2.Parameters.AddWithValue("?Name", Name.Text);
cmd2.Parameters.AddWithValue("?Address", address.Text);
cmd2.Parameters.AddWithValue("?Phone", phoneNo.Text);
cmd2.Parameters.AddWithValue("?Cell", CellNo.Text);
cmd2.Parameters.AddWithValue("?Email", email.Text);
cmd2.Parameters.AddWithValue("?DOB", dob.Text);
cmd2.Parameters.AddWithValue("?Commission", commission.Text);
cmd2.Parameters.AddWithValue("?Comments", comments.Text);
cmd2.Parameters.AddWithValue("?Photo", bytes);
cmd2.Parameters.AddWithValue("?User_ID", System.DBNull.Value);
cmd2.Parameters.AddWithValue("?IsActive", System.DBNull.Value);
conn.Open();
cmd2.ExecuteNonQuery();
conn.Close();
Response.Redirect("~/Views/Portal/Dashboard.aspx");
}
else
{
}
}
任何幫助將不勝感激。
您是否使用Oracle或Sql Server作爲數據庫? –
我正在使用Sql Server – EL323
使用'@'而不是'?'你是怎麼想到'?'實際上? – uTeisT