我遇到了c#中的一個問題。我正在嘗試從文本框中寫入數據到SQL Server Express 2012.我遇到了ExecuteNonQuery()問題;我的查詢一定有問題。這是代碼。SQL Server 2012. c#查詢出錯
void saveData()
{
try
{
var firstName = fNameTextbox.Text;
var lastName = LNameTextBox.Text;
var userName = UserName.Text;
String pass = PasswordTextBox.Password;
String confirm = ConfirmTextBox.Password;
int loggedIn = 1;
//parameterise values
string connectionString = @"Data Source=.\SQLEXPRESS;Integrated Security=True;User Instance=True";
using (SqlConnection connection = new SqlConnection(connectionString))
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = "INSERT INTO [EVUSERS] (UName, Pass, FName, LName, Attempts, LastLogin, LoggedIn) VALUES (@UName, @Pass, @FName, @LName, @Attempts, @LastLogin, @LoggedIn)";
command.Parameters.AddWithValue("@UName", UserName);
command.Parameters.AddWithValue("@Pass", pass);
command.Parameters.AddWithValue("@FName", firstName);
command.Parameters.AddWithValue("@LName", lastName);
command.Parameters.AddWithValue("@Attempts", attempts);
command.Parameters.AddWithValue("@LastLogin", lastLogIn);
command.Parameters.AddWithValue("@LoggedIn", loggedIn);
connection.Open();
command.ExecuteNonQuery();
MessageBox.Show("command number of rows = " + command);
}
//connection.Close();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
}
錯誤:
我想寫表。
想不通的問題。似乎在查詢中。不確定。謝謝。
HTTP://meta.stackexchange。 com/questions/10647/how-do-i-write-a-good-title –