TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
manoj kumar
NA
147
139.8k
Form
Dec 22 2009 5:14 AM
Hi pls help me...........
I want to insert data in sql server 2005...
i have textfield ,checklistbox....data all ready in sql.... bt checllist values does nt appear in sql server.......code is correct.... pls help me .......
using
System;
using
System.Configuration;
using
System.Data;
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.Data.SqlClient;
using
System.Data.SqlTypes;
public
partial
class
_Default
: System.Web.UI.
Page
{
string
Strlist1 =
""
, Strlist2 =
""
, Strlist3 =
""
, Strlist4 =
""
, Strlist5 =
""
, Strlist6 =
""
, Strlist7 =
""
;
string
a;
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
ValidateData()
{
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
ValidateData1()
{
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
ValidateData2()
{
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
ValidateData3()
{
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
ValidateData4()
{
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
ValidateData5()
{
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
ValidateData6()
{
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
(ValidateData())
{
if
(ValidateData1())
{
if
(ValidateData2())
{
if
(ValidateData3())
{
if
(ValidateData4())
{
if
(ValidateData5())
{
if
(ValidateData6())
{
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
Strdata =
ConfigurationManager
.ConnectionStrings[
"manoj1"
].ConnectionString;
SqlConnection
con =
new
SqlConnection
(Strdata);
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.Text;
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(
"@Schools"
,
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;
}
}
else
{
Response.Write(
false
);
}
}
}
Reply
Answers (
0
)
doubt(user account activation)
Alter Tables Using SMO