2017-06-28 6 views
0

ユーザー入力データを.csから表にインポートできません。私は2つのテーブルを1つはすべてのユーザーの詳細を取っている間、他のユーザー名(名)とパスワードを取る。パスワードとユーザー名を除いて、データは詳細テーブルに入ります。ここ は.csファイルからコードでWebフォームからデータベースにデータをインポートできません

パブリックパーシャルクラス申し込み:System.Web.UI.Page {保護されたボイドをPage_Load(オブジェクト送信者、のEventArgs電子) {

} 

    protected void btnReg_Click(object sender, EventArgs e) 
    { 
     string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; 


     using (SqlConnection con = new SqlConnection(cs)) 
     { 

      //string encryption = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "SHA1"); 
      SqlCommand cmd2 = new SqlCommand("sp_PasswordStorage", con); 
      SqlCommand cmd = new SqlCommand("sp_procedure", con); 
      cmd2.CommandType = CommandType.StoredProcedure; 
      cmd.CommandType = CommandType.StoredProcedure; 

      if (Page.IsValid) 
      { 
       cmd.Parameters.AddWithValue("@Fname", txtFname.Text); 
       cmd2.Parameters.AddWithValue("@uname", txtFname.Text); 
       cmd2.Parameters.AddWithValue("@pswd", Encryption(txtPassword.Text)); 
       cmd.Parameters.AddWithValue("@Lname", txtLname.Text); 
       cmd.Parameters.AddWithValue("@Age", txtAge.Text); 
       cmd.Parameters.AddWithValue("@eid", txtEmail.Text); 
       cmd.Parameters.AddWithValue("@pno", txtPhone.Text); 
       cmd.Parameters.AddWithValue("@city", txtCity.Text); 
       cmd.Parameters.AddWithValue("@country", txtCountry.Text); 
       cmd.Parameters.AddWithValue("@gender", dropGender.SelectedItem.Value); 
       cmd.Parameters.AddWithValue("@role", dropRole.SelectedItem.Value); 

       con.Open(); 
       cmd.ExecuteNonQuery(); 
       //MessageBox.Show("Registration successfully"); 
       Server.Transfer("MainPage.aspx", true); 
      } 
      else 
      { 
       MessageBox.Show("Registration Failed"); 
       MessageBox.Show("Please Try Again Later"); 
       Server.Transfer("MainPage.aspx", true); 
      } 
     } 
    } 
    public string Encryption(string value) 
    { 
     SHA1 algorithm = SHA1.Create(); 
     byte[] data = algorithm.ComputeHash(Encoding.UTF8.GetBytes(value)); 
     string sh1 = ""; 
     for (int i = 0; i < data.Length; i++) 
     { 
      sh1 += data[i].ToString("x2").ToUpperInvariant(); 
     } 
     return sh1; 
    } 

} 

}

助けていただければ幸いです。ありがとうございます:)

+1

何が起こると思われますか?実際に何が起こるのですか?実行時に例外が発生しますか? (もしそうなら、彼らは何ですか?) – mjwills

+0

'catch'でコードをラップする価値がありますか? – JonE

+1

現在のコードで何が問題になっていますか?何かエラーが出ますか?デバッグして、コード内で何が起きているか確認しましたか?データが挿入されているかどうかチェックしましたか? 'cmd2'ではなく' cmd'だけを実行しています。それに気づいた? –

答えて

2

私はそれが両方のコマンドを実行すると思います。

cmd.ExecuteNonQuery(); 
cmd2.ExecuteNonQuery(); 
+0

ありがとう、それは私の問題を解決:) –

関連する問題