-1

protected void Button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-0ADOEDB\SQLDEV2019;Initial Catalog=WebApplication;Integrated Security=True");

        SqlCommand com = new SqlCommand("Insert into Cust_Data values(@Name,@Gender, @Country, @State,@City,@Adress,@Email, @Contact)", con);
        con.Open();
        com.Parameters.AddWithValue("@Name", txtname.Text);
        com.Parameters.AddWithValue("@Gender", rdogenderlist.SelectedValue);
        com.Parameters.AddWithValue("@Country", txtcountry.Text);
        com.Parameters.AddWithValue("@State", txtstate.Text);
        com.Parameters.AddWithValue("@City", DropDownlist1.SelectedItem.Value);
        com.Parameters.AddWithValue("@Adress",txtadress.Text);
        com.Parameters.AddWithValue("@Email", txtemail.Text);
        com.Parameters.AddWithValue("@Contact", txtcontact);
       
        int i = com.ExecuteNonQuery();
        if (i == 1)
        {
            
            txtname.Text = "";
            rdogenderlist.SelectedValue = String.Empty;
            txtcountry.Text = " ";
            txtstate.Text = " ";
            DropDownlist1.SelectedValue = String.Empty;
            txtadress.Text = " ";
            txtemail.Text = " ";
            txtcontact.Text = " ";


        }
      
        con.Close();







    }
Dee
  • 11
  • 1

1 Answers1

0

Your code contains a typo.

com.Parameters.AddWithValue("@Contact", txtcontact);

should be

com.Parameters.AddWithValue("@Contact", txtcontact.Text);

That's an error anyway, I can't guarantee the code works as you intended if you correct this.

tim-
  • 184
  • 6