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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Mar 2, 2012, 8:53 PM EST
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