1

これは、テキストフィールドからデータベースに挿入するための私のコードです。

SqlConnection Connection = new SqlConnection("Data Source=ESHA\\SQLEXPRESS;Initial Catalog=Gen_Lic;User ID=sa;Password=sa@");           

SqlCommand Command = Connection.CreateCommand();

try
{
// Open Connection             
Connection.Open();
////Console.WriteLine("Connection Opened");
// Create INSERT statement with named parameters             
Command.CommandText = "INSERT  INTO Gen_Lic(Lic_No, UserID, Org, UserName, SolType, Version, Lic_Type, Meap_Supp, Lic_From, Lic_To, Supp_From, Supp_To, Max_User, Max_Mach, Mach_IP, Mach_MAC) VALUES (@Lic_No, @UserID, @Org, @UserName, @SolType, @Version, @Lic_Type, @Meap_Supp, @Lic_From, @Lic_To, @Supp_From, @Supp_To, @Max_User, @Max_Mach, @Mach_IP, @Mach_MAC)";
// Add Parameters to Command Parameters collection  

Command.Parameters.AddWithValue("@Lic_No", txtLNo.Text);
Command.Parameters.AddWithValue("@UserID", txtUID.Text);
Command.Parameters.AddWithValue("@Org", txtOrg.Text);
Command.Parameters.AddWithValue("@UserName", txtUName.Text);
Command.Parameters.AddWithValue("@SolType", txtSType.Text);
Command.Parameters.AddWithValue("@Version", txtVer.Text);
Command.Parameters.AddWithValue("@Lic_Type", drpLType.SelectedItem.Text);
Command.Parameters.AddWithValue("@Meap_Supp", rdoMeapSupport.SelectedValue.ToString());
Command.Parameters.AddWithValue("@Lic_From", lblLFrom.Text);
Command.Parameters.AddWithValue("@Lic_To", lblLTo.Text);
Command.Parameters.AddWithValue("@Supp_From", lblSuppFrom.Text);
Command.Parameters.AddWithValue("@Supp_To", lblSuppTo.Text);
Command.Parameters.AddWithValue("@Max_User", txtMaxUsr.Text);
Command.Parameters.AddWithValue("@Max_Mach", txtMaxMach.Text);
Command.Parameters.AddWithValue("@Mach_IP", txtMachIP.Text);
Command.Parameters.AddWithValue("@Mach_MAC", txtMachMac.Text);

Connection.Close();

}

問題は、コードが正常に機能していることですが、値がデータベースに挿入されていません。また、接続形成の開始時にブレークポイントを適用すると、新しい空白の IE ウィンドウが開きます。

誰かが私がどこで間違っているのか教えてもらえますか?

4

2 に答える 2

6

私は、次のものが欠けていると思います:

Command.ExecuteNonQuery(); 

の前にConnection.Close()

于 2012-11-27T07:18:32.830 に答える
1

データベースに対してこのクエリを再度実行してください

Command.ExecuteNonQuery();

接続を閉じる前に

于 2012-11-27T07:18:45.917 に答える