2014-09-28 49 views
0

我一直在處理從ASP.NET頁面連接到數據庫的問題。我填補了相關的登記表後,我已經準備好,當我點擊完成註冊,我遇到了一個錯誤:通過使用ASP.NET將元素插入數據庫表

enter image description here

這裏是我的代碼:

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; 
       } 
      } 
     } 
    } 
+1

你應該張貼與堆棧跟蹤整個例外,而不是隻圖像的執行被拋出。它有助於調試。 – Yasser 2014-09-28 06:12:32

+0

好的我現在正在編輯 – user3708524 2014-09-28 07:28:31

+0

沒關係,那編輯不會被批准:P – Yasser 2014-09-28 08:00:40

回答

1

這似乎是數據庫連接問題。在你的連接字符串中,你沒有指定數據庫用戶名和密碼。

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

這意味着除了必須在這條線上baglanti.Open();

相關問題