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
sandeep sandy
NA
18
7.2k
auto generate the id after data sucessfully inserted
May 11 2016 7:35 AM
HI,
the id should auto incremented after the data inserted into database,
here in my code after page refresh id is increasing can u modify my code and send it,
thanks in advance
----------------------------------------------------------------------------------------------
namespace Help_Desk
{
public partial class WebForm2 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
//string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string str;
SqlCommand com;
int count;
protected void Page_Load(object sender, EventArgs e)
{
//SqlConnection con = new SqlConnection(strConnString);
str = "select count(*) from employee1";
com = new SqlCommand(str, con);
con.Open();
count = Convert.ToInt16(com.ExecuteScalar()) + 1;
txt_empid.Text = "E00" + count;
con.Close();
}
protected void btn_insert_Click(object sender, EventArgs e)
{
//SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "insert into employee1 values('" + txt_empid.Text.Trim() + "','" + txt_empname.Text.Trim() + "'," + txt_sal.Text.Trim() + ")";
com = new SqlCommand(str, con);
com.ExecuteNonQuery();
con.Close();
Label4.Text = "Records successfully Inserted";
}
}
}
------------------------------------------------------------------------------------------------------------------------
Reply
Answers (
2
)
html in textbox
MVC Multi Level Menu from database