我想下面的代碼:無法插入一排參數
try
{
SqlConnection conn = new SqlConnection("server=ARSLAN-LAPI\\SQLEXPRESS;" +
"Trusted_Connection=yes;" +
"database=OTTS; " +
"connection timeout=30");
conn.Open();
String name=UserName.Text;
String pwd=Password.Text;
String query = "INSERT INTO dbo.user (username,password)
VALUES(@username,@password)";
SqlCommand command = new SqlCommand(query, conn);
command.Parameters.Add("@username",name);
command.Parameters.Add("@password",pwd);
command.ExecuteNonQuery();
conn.Close();
ErrorMessage.Text="Well done!";
}
catch(SqlException ex)
{
ErrorMessage.Text="You failed!" + ex.Message;
}
收到錯誤
You failed!Incorrect syntax near the keyword 'user'.
請指導我..
雖然正確,你應該解釋更多。 – DavidG