Wenn ich versuche, meine Formulardaten in sql
Datenbank auf Knopfdruck zu speichern, ist Daten nicht in der Tabelle speichern. Hier ist meine web.config
Datei und Code hinter der Datei.Daten werden nicht eingefügt
web.config:
<connectionStrings>
<add name="conn" connectionString="Data Source=admin-pc\SQLEXPRESS;database=abc;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
Hier mein Code hinter Datei ist aspx.cs:
public partial class registration : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=admin-pc\SQLEXPRESS ; Database=abc; Integrated Security=true");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
txtFistname.Text = "";
txtlastname.Text = "";
TextBox1.Text = "";
txtEmail.Text = "";
txtcontac.Text = "";
txtPassword.Text = "";
txtconPassword.Text = "";
SqlCommand cmd = new SqlCommand("insert into reg(FName,LName,Gender,email,contact,password,conpasswd) values('" + txtFistname.Text + "','" + txtlastname.Text + "','" + TextBox1.Text + "','" + txtEmail.Text + "','" + txtcontac.Text + "','" + txtPassword.Text + "','" + txtconPassword.Text + "')", con);
cmd.CommandType = CommandType.Text;
try
{
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
Response.Write("Data inserted successfully");
}
}
}