hi, im trying to insert data using Checklist and it is only inserting one even if i selected all che checkboxes, please help.hr is my Code
protected void Button1_Click(object sender, EventArgs e)
{
//C:\Documents and Settings\PraiseM\My Documents\Visual Studio 2008\Projects\MiniProjectAcc\MiniProjectAcc\Employee.accdb
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\PraiseM\My Documents\Visual Studio 2008\Projects\MiniProjectAcc\MiniProjectAcc\Employee.accdb";
string LastName = txtEmp_LastName.Text;
string FirstName = txtEmployeeName.Text;
string Email = txtEmail.Text;
string Phone = txtPhone.Text;
string Address = txtAddress.Text;
string Street = txtStreet.Text;
string Code = txtCode.Text;
string Roles = CheckBoxList1.Text;
string Password = txtPass.Text;
OleDbCommand cmd = new OleDbCommand("INSERT INTO tblEmployee (LastName, FirstName, Email, Phone, Address, Street, Code, Roles, [Password]) Values(@LastName, @FirstName, @Email, @Phone, @Address, @Street, @Code, @Roles, @Password)");
cmd.Connection = conn;
conn.Open();
if (conn.State == ConnectionState.Open)
{
string Emp_role = "";
for (int a = 0; a < CheckBoxList1.Items.Count - 1; a++)
{
if (CheckBoxList1.Items[a].Selected)
{
Emp_role += CheckBoxList1.Items[a].Text.ToString() + ",";
}
}
cmd.Parameters.Add("@LastName", OleDbType.VarChar).Value = LastName;
cmd.Parameters.Add("@FirstName", OleDbType.VarChar).Value = FirstName;
cmd.Parameters.Add("@Email", OleDbType.VarChar).Value = Email;
cmd.Parameters.Add("@Phone", OleDbType.VarChar).Value = Phone;
cmd.Parameters.Add("@Address", OleDbType.VarChar).Value = Address;
cmd.Parameters.Add("@Street", OleDbType.VarChar).Value = Street;
cmd.Parameters.Add("@Code", OleDbType.VarChar).Value = Code;
cmd.Parameters.Add("@Roles", OleDbType.VarChar).Value = Roles;
cmd.Parameters.Add("@Password", OleDbType.VarChar).Value = Password;
try
{
cmd.ExecuteNonQuery();
lblDisplay.Text = ("Data Added");
conn.Close();
}
catch (OleDbException ex)
{
conn.Close();
}
}
else
{
lblDisplay.Text = ("Connection Failed");
}
}