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
anil wagavkar
NA
13
5.6k
how to avoid to insert duplicate data in db.
Mar 23 2016 5:29 AM
when i insert the data i have error exception."
The connection was not closed. The connection's current state is open.
"
here is my code.
protected void Button3_Click(object sender, EventArgs e)
{
SqlDataAdapter da;
string qry = "select * from salesmans_master where rankuser=" + salesuserid.Text;
da = new SqlDataAdapter(qry, con);
con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
Label15.Text = "this salesid is already present.";
}
else
{
SqlCommand cmd = new SqlCommand("insert into salesmans_master(name,addressof,rankuser,rankcode)values('" + salesname.Text + "','" + salesadderss.Text + "','" + salesuserid.Text + "','" + DropDownList1.SelectedValue + "')", con);
try
{
con.Open();
cmd.ExecuteNonQuery();
Label15.Text = "data Inserted";
con.Close();
}
catch (Exception ex)
{
Label15.Text = ex.Message;
}
}
Reply
Answers (
3
)
regular expresion validator
C# Application runs in Windows 10 but not Windows Vista