Hi I am using this code for insert data in sql..
code is correct.and data is also insert in database bt some field of Checkboxlist in
this form..chechboxlist record is not show in data base..checkboxlist columns show emthy in database...wt happen ...i dnt know pls help some one.......
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.SqlTypes;
public partial class _Default : System.Web.UI.Page
{
string a;
string Strlist1 = "", Strlist2 = "", Strlist3 = "", Strlist4 = "", Strlist5 = "", Strlist6 = "", Strlist7 = "";
protected void Page_Load(object sender, EventArgs e)
{
string database = ConfigurationManager.ConnectionStrings["manoj"].ConnectionString;
SqlConnection con = new SqlConnection(database);
SqlDataAdapter da = new SqlDataAdapter("select Industry,EFairs,School,PendingSchool,DisplayTextLink,Permission,Flags from Master_EditEmp", con);
DataSet ds = new DataSet();
da.Fill(ds, "table");
CheckBoxList1.DataSource = ds.Tables[0];
CheckBoxList1.DataTextField = ds.Tables[0].Columns["Industry"].ColumnName.ToString();
CheckBoxList1.DataValueField = ds.Tables[0].Columns["Industry"].ColumnName.ToString();
CheckBoxList1.DataBind();
chkEflair.DataSource = ds.Tables[0];
chkEflair.DataTextField = ds.Tables[0].Columns["EFairs"].ColumnName.ToString();
chkEflair.DataValueField = ds.Tables[0].Columns["EFairs"].ColumnName.ToString();
chkEflair.DataBind();
chkschool.DataSource = ds.Tables[0];
chkschool.DataTextField = ds.Tables[0].Columns["School"].ColumnName.ToString();
chkschool.DataValueField = ds.Tables[0].Columns["School"].ColumnName.ToString();
chkschool.DataBind();
chkpenschool.DataSource = ds.Tables[0];
chkpenschool.DataTextField = ds.Tables[0].Columns["PendingSchool"].ColumnName.ToString();
chkpenschool.DataValueField = ds.Tables[0].Columns["PendingSchool"].ColumnName.ToString();
chkpenschool.DataBind();
chkdisplay.DataSource = ds.Tables[0];
chkdisplay.DataTextField = ds.Tables[0].Columns["DisplayTextLink"].ColumnName.ToString();
chkdisplay.DataValueField = ds.Tables[0].Columns["DisplayTextLink"].ColumnName.ToString();
chkdisplay.DataBind();
chkpermission.DataSource = ds.Tables[0];
chkpermission.DataTextField = ds.Tables[0].Columns["Permission"].ColumnName.ToString();
chkpermission.DataValueField = ds.Tables[0].Columns["Permission"].ColumnName.ToString();
chkpermission.DataBind();
chkflags.DataSource = ds.Tables[0];
chkflags.DataTextField = ds.Tables[0].Columns["Flags"].ColumnName.ToString();
chkflags.DataValueField = ds.Tables[0].Columns["Flags"].ColumnName.ToString();
chkflags.DataBind();
if(rbstatus.Checked==true)
{
a="Disabled";
}
else if(rbstatus1.Checked==true)
{
a="Enabled";
}
}
private bool validate1()
{
int counter = 0;
foreach (ListItem li in CheckBoxList1.Items)
{
if (li.Selected)
{
counter = counter + 1;
Strlist1 = Strlist1 + " " + li.Text;
}
}
if (counter > 2)
{
return false;
}
else
{
return true;
}
}
private bool validate2()
{
int counter = 0;
foreach (ListItem li in chkEflair.Items)
{
if (li.Selected)
{
counter = counter + 1;
Strlist2 = Strlist2 + " " + li.Text;
}
}
if (counter > 2)
{
return false;
}
else
{
return true;
}
}
private bool validate3()
{
int counter = 0;
foreach (ListItem li in chkschool.Items)
{
if (li.Selected)
{
counter = counter + 1;
Strlist3 = Strlist3 + " " + li.Text;
}
}
if (counter > 2)
{
return false;
}
else
{
return true;
}
}
private bool validate4()
{
int counter = 0;
foreach (ListItem li in chkpenschool.Items)
{
if (li.Selected)
{
counter = counter + 1;
Strlist4 = Strlist4 + " " + li.Text;
}
}
if (counter > 2)
{
return false;
}
else
{
return true;
}
}
private bool validate5()
{
int counter = 0;
foreach (ListItem li in chkdisplay.Items)
{
if (li.Selected)
{
counter = counter + 1;
Strlist5 = Strlist5 + " " + li.Text;
}
}
if (counter > 2)
{
return false;
}
else
{
return true;
}
}
private bool validate6()
{
int counter = 0;
foreach (ListItem li in chkpermission.Items)
{
if (li.Selected)
{
counter = counter + 1;
Strlist6 = Strlist6 + " " + li.Text;
}
}
if (counter > 2)
{
return false;
}
else
{
return true;
}
}
private bool validate7()
{
int counter = 0;
foreach (ListItem li in chkflags.Items)
{
if (li.Selected)
{
counter = counter + 1;
Strlist7 = Strlist7 + " " + li.Text;
}
}
if (counter > 2)
{
return false;
}
else
{
return true;
}
}
private bool check()
{
if (validate1())
{
if (validate2())
{
if (validate3())
{
if (validate4())
{
if (validate5())
{
if (validate6())
{
if (validate7())
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
}
protected void btnsave_Click(object sender, EventArgs e)
{
if (check())
{
string data = ConfigurationManager.ConnectionStrings["manoj"].ConnectionString;
SqlConnection con = new SqlConnection(data);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Edit";
cmd.Parameters.Add("@AccountManager", SqlDbType.VarChar).Value = txtaccountmgr.Text;
cmd.Parameters.Add("@AccountManagerContact", SqlDbType.VarChar).Value = txtmgrcontact;
cmd.Parameters.Add("@Remarks", SqlDbType.VarChar).Value = txtremarks.Text;
cmd.Parameters.Add("@CompanyName", SqlDbType.VarChar).Value = txtcompany.Text;
cmd.Parameters.Add("@ShortName", SqlDbType.VarChar).Value = txtshortname.Text;
cmd.Parameters.Add("@BusinessRegNo", SqlDbType.VarChar).Value = txtbusiness.Text;
cmd.Parameters.Add("@Description", SqlDbType.VarChar).Value = txtdes.Text;
cmd.Parameters.Add("@Industry", SqlDbType.VarChar).Value = Strlist1;
cmd.Parameters.Add("@ContactPerson", SqlDbType.VarChar).Value = txtconperson.Text;
cmd.Parameters.Add("@Tel", SqlDbType.Int).Value = txttel.Text;
cmd.Parameters.Add("@Fax", SqlDbType.Int).Value = txtfax.Text;
cmd.Parameters.Add("@Website", SqlDbType.VarChar).Value = txtweb.Text;
cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value = txtemail.Text;
cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = txtpass.Text;
cmd.Parameters.Add("@Address", SqlDbType.VarChar).Value = txtadd.Text;
cmd.Parameters.Add("@EFairs", SqlDbType.VarChar).Value = Strlist2;
cmd.Parameters.Add("@School", SqlDbType.VarChar).Value = Strlist3;
cmd.Parameters.Add("@PendingSchools", SqlDbType.VarChar).Value = Strlist4;
cmd.Parameters.Add("@DisplayTextLink", SqlDbType.VarChar).Value = Strlist5;
cmd.Parameters.Add("@Status", SqlDbType.VarChar).Value = a;
cmd.Parameters.Add("@Permission", SqlDbType.VarChar).Value = Strlist6;
cmd.Parameters.Add("@Flags", SqlDbType.VarChar).Value = Strlist7;
cmd.Parameters.Add("@Designation", SqlDbType.VarChar).Value = txtdesig.Text;
cmd.Connection = con;
try
{
con.Open();
cmd.ExecuteNonQuery();
Response.Write(true);
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
}
}
}
}