Hardik Patel

Hardik Patel

  • NA
  • 378
  • 469.4k

error during insert data in 2007 access database?

Aug 29 2013 1:28 AM
below code not working for insert data

string r;
        r = "";
        if (RadioButton1.Checked == true)
        {
            r = "Male";
        }
        else if (RadioButton2.Checked == true)
        {
            r = "Female";
        }
        con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\mydb.accdb");
        con.Open();
        com = new OleDbCommand();
        com.Connection = con;
        com.CommandType = CommandType.Text;
       com.CommandText = "insert into Table1 values(@Sname,@Dbo,@gender,@address,@district,@Taluka,@town,@phoneno,@mobileno,@qualification,@pyear,@percentage,@income,@expenses)";
        //com.CommandText ="insert into Table1 values(@Sname,@Dbo,@gender,@address)";
        com.Parameters.Clear();
        com.Parameters.AddWithValue("@Sname",txtName.Text);
        com.Parameters.AddWithValue("@Dbo", Convert.ToDateTime(TextBox3.Text).ToString("dd/mm/yyyy"));
        com.Parameters.AddWithValue("@gender", r.ToString());
        com.Parameters.AddWithValue("@address", txtAddress.Text);
        com.Parameters.AddWithValue("@district", ddlstate.SelectedItem.Text);
        com.Parameters.AddWithValue("@Taluka", ddlcity.SelectedItem.Text);
        com.Parameters.AddWithValue("@town", TextBox1.Text);
        com.Parameters.AddWithValue("@phoneno", txtUserName.Text);
        com.Parameters.AddWithValue("@mobileno", txtPassword.Text);
        com.Parameters.AddWithValue("@qualification", txtRetypePassword.Text);
        com.Parameters.AddWithValue("@pyear", TextBox4.Text);
        com.Parameters.AddWithValue("@percentage", TextBox2.Text);
        com.Parameters.AddWithValue("@income", TextBox5.Text);
        com.Parameters.AddWithValue("@expenses", TextBox6.Text);

        if (con.State == ConnectionState.Closed)
            con.Open();
        com.ExecuteNonQuery();
        con.Close();
        Response.Redirect("Scholarship.aspx");


Answers (1)