Friends............. I create a code for Autogenerate Employee no. filename : autogenerate DataBase name in SQL Server : employee Table name : emp. It displays a 1error. Plz Solve this........... using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; namespace WebApplication3 { public partial class autogenerate : System.Web.UI.Page { string eno = eno_; int i; protected void Page_Load(object sender, EventArgs e) { if (IsPostBack == false) { AutogenerateEmployeeno(); } } void AutogenarateEmployeeno() { SqlConnection con = new SqlConnection(userid=sa;password=abc;datasource=GOD-PC;database=employee); con.Open(); SqlCommand cmd = new SqlCommand(select count(*)from employee, con); int i = Convert.ToInt32(cmd.ExecuteScalar()); i++; eno = eno + i; TextBox1.Text = eno; } protected void Button1_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.Open(); string query = insert into employee values( + TextBox1.Text + , + TextBox2 + , + TextBox3.Text + ); SqlCommand cmd = new SqlCommand(query, con); if(i==1) { Label1.Text=Record is Inserted; } else { Label1.Text=Insertion Failed; } con.Close(); AutogenarateEmployeeno(); TextBox2.Text= ; TextBox3.Text= ; } } }
Posted on: Sat, 06 Dec 2014 10:57:51 +0000