How to find already exist customer id?
pls tell me with example.
Loading
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 3, 2012, 1:53 AM
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Know_user_id_exits._Default" %>
using System;
using System.Collections;
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;
namespace Know_user_id_exits
{
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlDataAdapter sqlda;
SqlCommand com;
string str;
DataSet ds;
protected void btn_add_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "select * from student";
sqlda = new SqlDataAdapter(str, con);
ds = new DataSet();
sqlda.Fill(ds, "student");
int newid;
newid = Convert.ToInt32(txtid.Text.ToString());
if (!checkIfUnique(newid))
{
Response.Write("ID Already exists!");
txtid.Focus();
return;
}
else
{
str = "insert into student values (" + txtid.Text + ",'" + txtname.Text + "','" + txtaddress.Text + "')";
com = new SqlCommand(str, con);
com.ExecuteNonQuery();
}
con.Close();
}
private bool checkIfUnique(int newid)
{
int oldid;
foreach (DataRow r in ds.Tables["student"].Rows)
{
oldid = Convert.ToInt32(r["sid"]);
if (oldid == newid)
return false;
}
return true;
}
}
}
Thanks
If this post helps you mark it as answer