なぜこれがデータベースに値を追加しないのか誰かに教えてもらえますか?フォームは正常に実行され、エラーは返されません。
private void button1_Click(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection();
SqlCommand command = new SqlCommand();
connection.ConnectionString = (@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\John\Documents\Setup.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
command.Parameters.AddWithValue("@userName", textBox1.Text);
command.Parameters.AddWithValue("@passWord", textBox2.Text);
command.CommandText = "INSERT INTO Setup (userName, password) VALUES(@userName, @passWord)";
try
{
connection.Open();
int rowsAffected = command.ExecuteNonQuery();
}
catch (Exception ex)
{
// handle exception
}
finally
{
connection.Close();
}
}
参考:私は「初心者」です。私のデータベースはセットアップと呼ばれています。2列のuserNameを持つmyTableというテーブルと、パスワードと呼ばれる別のテーブルを手動で追加しました。どちらもnchar(50)に設定されています。