how to auto increment a varchar column value in C#
I want to auto increment a column value like P1,P2,P3.......and so on in windows C#
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Mar 8, 2013, 8:51 AM
Run the attachments.
Gopal MahadakPosted Mar 9, 2013, 5:25 AM
Mustaq KhanPosted Mar 9, 2013, 4:44 AM
Mustaq KhanPosted Mar 9, 2013, 1:12 AM
Mustaq KhanPosted Mar 8, 2013, 8:38 AM
what is lbl_castecode
Satyapriya NayakPosted Mar 8, 2013, 8:06 AM
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Dynamic_generate_id
{
public partial class Form1 : Form
{
string ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["dsn"];
OleDbCommand com;
string str;
int count;
public Form1()
{
InitializeComponent();
}
private void btn_save_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(ConnectionString);
con.Open();
str = "insert into caste(cast_code,cast_desc) values('" + lbl_castecode.Text.Trim() + "','" + txt_castename.Text.Trim() + "')";
com = new OleDbCommand(str, con);
com.ExecuteNonQuery();
con.Close();
MessageBox.Show("Records successfully Inserted");
txt_castename.Text = "";
autogenerated();
}
private void autogenerated()
{
OleDbConnection con = new OleDbConnection(ConnectionString);
str = "select count(*) from caste";
com = new OleDbCommand(str, con);
con.Open();
count = Convert.ToInt16(com.ExecuteScalar()) + 1;
lbl_castecode.Text = "P" + count.ToString();
lbl_castecode.Enabled = false;
con.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
autogenerated();
}
}
}