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
george wambui
NA
17
39.6k
How do i increment a number using c# after i have saved it into the database
Jun 11 2012 2:02 AM
Hi team,
Am having the following the code in c# and i want to increment the number through text box, so when i save the number it should increment automatically, and also when i open the web page again after i have closed it, it should retrieve the previous number which i saved in the database last.
Here is the code:
using System;
using System.Collections;
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.Odbc;
public partial class staffcode : System.Web.UI.Page
{
int num = 001;
OdbcCommand cmd;
OdbcConnection conn = new OdbcConnection("dsn=parcel;uid=dba;pwd=sql");
protected void Page_Load(object sender, EventArgs e)
{
//if (!Page.IsPostBack)
//{
//}
//getLastID();
}
protected void Btnsave_Click(object sender, EventArgs e)
{
OdbcCommand cmd;
OdbcConnection conn = new OdbcConnection("dsn=parcel;uid=dba;pwd=sql");
conn.Open();
cmd = new OdbcCommand("insert into tbl_staffcode(staffcode,fullname,desgination) values ('" + Txtcode.Text + "','" + txtname.Text + "','" + DropDownList1.Text + "')", conn);
//if (System.Windows.Forms.MessageBox.Show("confrim the data", "prompt", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
cmd.ExecuteNonQuery();
insert();
conn.Close();
}
private void insert()
{
string count = Txtcode.Text;
if (count.Length == 000)
{
Txtcode.Text = "001";
}
else
{
int count1 = Convert.ToUInt16(count);
int countAdd = count1 + 001;
Txtcode.Text = countAdd.ToString();
}
}
Regards
George
Reply
Answers (
2
)
c# winforms - multipleForms task
Difference Between VB and VB.NET