I'm new to access. I have created table in MS Access 2007 with following fields.
ID No, Name, Address, Gender, Favorite_Food
I want to create form to insert data into tables. I have used option buttons for Gender and Check boxes for Favorite Food.
But data didn't insert to the table specially option button and check boxes data didn't insert but other data successfully inserted into the table. Please someone help me
Thanks
Christian NwambaPosted Aug 23, 2013, 10:46 AM
Christian NwambaPosted Aug 23, 2013, 10:44 AM
Satyapriya NayakPosted Apr 28, 2013, 4:59 AM
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
namespace
{
public partial class WebForm3 : System.Web.UI.Page
{
OleDbConnection con;
OleDbCommand com;
protected void btn_insert_Click(object sender, EventArgs e)
{
con = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = D:\\mydb.mdb");
con.Open();
com = new OleDbCommand();
com.Connection = con;
com.CommandType = CommandType.Text;
com.CommandText = "insert into Table1 values(@IDNo,@Name,@Address,@Gender,@Favorite_Food)";
com.Parameters.Clear();
com.Parameters.AddWithValue("@IDNo", TextBox1.Text);
com.Parameters.AddWithValue("@Name", TextBox2.Text);
com.Parameters.AddWithValue("@Address", TextBox3.Text);
com.Parameters.AddWithValue("@Gender", rbtGender.SelectedValue);
com.Parameters.AddWithValue("@Favorite_Food", CheckBoxList1.SelectedValue);
if (con.State == ConnectionState.Closed)
con.Open();
com.ExecuteNonQuery();
con.Close();
lblmsg.Text = "Data entered successfully!!!";
}
}
}