user3708524
user3708524

Reputation: 27

Inserting elements into a database table through using ASP.NET

I have been dealing with connecting to a database from an ASP.NET page. After I had filled the associated the registration form I have prepared, when I click the complete registration I am encountering an error:

enter image description here

And here is my code:

protected void Button1_Click(object sender, EventArgs e)   
{
       using (SqlConnection baglanti = new SqlConnection("server=BerkPC-IV; Initial Catalog=Okul; Integrated Security=true;"))
       {
           using (SqlCommand komut = new SqlCommand())
           {
                komut.Parameters.AddWithValue("@name", TextBox1.Text);
                komut.Parameters.AddWithValue("@midname", TextBox2.Text);
                komut.Parameters.AddWithValue("@surname", TextBox3.Text);
                komut.Parameters.AddWithValue("@phone", TextBox4.Text);
                komut.Parameters.AddWithValue("@country", TextBox5.Text);
                komut.Parameters.AddWithValue("@city", TextBox6.Text);
                komut.Parameters.AddWithValue("@adress", TextBox7.Text);
                komut.Parameters.AddWithValue("@passwod", TextBox8.Text);
                komut.Parameters.AddWithValue("@email", TextBox9.Text);

                try
                {
                    baglanti.Open();
                    komut.ExecuteNonQuery();
                }
                catch (SqlException ex)
                {
                    throw;
                }
            }
        }
    }

Upvotes: 0

Views: 47

Answers (1)

Yasser Shaikh
Yasser Shaikh

Reputation: 47774

This seems like a db connectivity issue. In your connection string you have not specified the db username and password.

new SqlConnection("server=BerkPC-IV; Initial Catalog=Okul; Integrated Security=true;"))

which mean the exception must be thrown on execution of this line baglanti.Open();

Upvotes: 1

Related Questions