Window Form C#
How to generate Auto Registration no. in Window form c# ado.net???
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.
Deoraj SharmaPosted Feb 2, 2013, 12:43 PM
Satyapriya NayakPosted Feb 2, 2013, 5:08 AM
Create table employee(empid varchar(50) primary key,empname varchar(50),sal int)
Default.aspx code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Default.aspx.cs code
using System;
using System.Configuration;
using System.Data;
using System.Linq;
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.Xml.Linq;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
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 employee";
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 employee 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";
}
}
Gopal MahadakPosted Feb 2, 2013, 4:53 AM
oledbconnection con=new oledbconnection(string connection);
con.open();
oledbcommand cmd=new oledbcommand("select max(regno) from table",con)
oledbdatareader dr=cmd.executereader();
while(dr.read()==true)
{
text1.text=dr["regno"].tostring();
}
read it in form load gives u autoincremented result