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
saifullah khan
NA
335
301.9k
registration form
Apr 8 2011 3:30 AM
hello!
i am creating a registration form, which first identifies if the user is exist or not if not then it add the data of user in database. but it is giving following error.
SqlConnection con = new SqlConnection("Data Source=EMINENCE-PC\\SQLEXPRESS;Initial Catalog=iitkust;Integrated Security=True");
SqlCommand cmd;
SqlDataReader dr;
protected void SignUp_Click(object sender, EventArgs e)
{
con.Open();
cmd = new SqlCommand("select * from Reg where UserName='" + UserName.Text + "' ", con);
dr = cmd.ExecuteReader();
if (dr.Read())
{
Label1.Text = "User exist";
con.Close();
}
else
{
con.Open();
if (!dr.Read())
{
cmd = new SqlCommand("insert into Reg values('" + UserName.Text + "','" + FirstName.Text + "','" + LastName.Text + "','" + UIDNo.Text + "','" + Discipline.Text + "','" + Department.Text + "','" + Email.Text + "','" + Password.Text + "','" + ConfermPassword.Text + "','" + Contact.Text + "')", con);
cmd.ExecuteNonQuery();
con.Close();
return;
the output gives the following error:
Exception Details: System.InvalidOperationException: The connection was not closed. The connection's current state is open.
Source Error:
Line 30: else
Line 31: {
Line 32: con.Open();
Line 33: if (!dr.Read())
Line 34: {
please tell me the solution
Reply
Answers (
5
)
How to Get child control In Datalist?
sms send using asp.net and not use of web services or gate way