データベースに接続しようとしましたが、「null」エラーが表示されます。というわけで、練習した前のフォームを開いてみると、全然大丈夫でした。
これは私のコードです:
string username = txtusername.Text;
        string firstname = txtfirstname.Text;
        string lastname = txtlastname.Text;
        string email = txtemail.Text;
        string password = txtpass.Text;
        string gender = rbgender.Text;
        string nationality = dcountry.Text;
        string phone = txtphone.Text;
        string connection = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;
        SqlConnection connect = new SqlConnection(connection);
        string command = "INSERT INTO Persons(username, firstname, lastname, email, password, gender, nationality, phone) VALUES('@username','@firstname','@lastname','@email','@password','@gender','@nationality','@phone')";
        SqlCommand insert = new SqlCommand(command +","+ connection);
        insert.Parameters.AddWithValue("@username", username);
        insert.Parameters.AddWithValue("@firstname", firstname);
        insert.Parameters.AddWithValue("@lastname", lastname);
        insert.Parameters.AddWithValue("@email", email);
        insert.Parameters.AddWithValue("@password", password);
        insert.Parameters.AddWithValue("@gender", gender);
        insert.Parameters.AddWithValue("@nationality", nationality);
        insert.Parameters.AddWithValue("@phone", phone);
        insert.ExecuteNonQuery();
        connect.Close();
web.config の接続文字列と関係がありますか?
 <connectionStrings>
<add name="ApplicationServices"
     connectionString="Data Source=ADRIAN-LAPTOP\SQL;Initial Catalog=New;Integrated Security=True"
     providerName="System.Data.SqlClient" />