Click here to Skip to main content
14,603,943 members
Rate this:
Please Sign up or sign in to vote.
See more:
Dear all,

This is My table
rtnumber weldnumber jointnumber weldjointnumber
1 1 1 1-1
2 1 2 1-2
3 1 3 1-3
4 1 4 1-4
5 1 5 1-5
6 1 1 1-1 This time i want show error messange,this datas are already available.
7 2 1 2-1
8 2 2 2-2
9 2 3 2-3
10 2 4 2-4
11 2 5 2-5
12 2 1 2-1This time i want show error messange,this datas are already available.
13 3 1 3-1
14 3 2 3-2
15 3 3 3-3
16 3 4 3-4
17 3 5 3-5
18 3 2 3-2This time i want show error messange,this datas are already available.


My Question:

when i will add data into data table first time it will insert(1,1,1-1),same existing data(1,1,1-1) when i will add second time,this time i want show error message based on the weldnumber and jointnumber columns.

Kindly anybody help me.

ragards
samy
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

Create one method to check record exists
private boolean IsRecordExists(int weldnumberValue , int jointnumberValue)
{
//Select rtnumber from mytable where weldnumber= "+weldnumbeValue +" and  jointnumber= "+jointnumberValue+"
//Get values in dataset
//Check dataset table row count
//if 1 return true else false

}


use this method like this

if(!IsRecordExists(1,1))
{
//Data insert code
}
else
{
//Error:Data already available
}
   
Comments
samy555 26-Nov-12 7:57am
   
private boolean IsRecordExists(int weldnumberValue, int jointnumberValue)
{
SqlConnection cn = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
SqlCommand Comm1 = new SqlCommand("Select rtnumber from mytable where weldnumber= " + weldnumbeValue + " and jointnumber= " + jointnumberValue + "", cn);
SqlDataAdapter ad = new SqlDataAdapter(Comm1);
DataSet ds = new DataSet();
ad.Fill(ds);
string str = string.Empty;
if (ds.Tables.Count > 1)
{
if (ds.Tables[0].Rows.Count > 1)
{
str = "Vales are Available!Enter it.";
}
}
else
{
str = "Vales are already exists!Please Choose another value.";
}
}

This above coding is correct or any changes is available.
pradiprenushe 27-Nov-12 0:59am
   
else should be for inner if like this
if (ds.Tables.Count > 1) {
if (ds.Tables[0].Rows.Count == 0)
{
str = "Vales are Available!Enter it.";
}
else
{
str = "Vales are already exists!Please Choose another value.";
}
}
Rate this:
Please Sign up or sign in to vote.

Solution 2

private boolean IsRecordExists(int weldnumberValue, int jointnumberValue)
{
SqlConnection cn = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);

SqlCommand Comm1 = new SqlCommand("Select rtnumber from mytable where weldnumber= " + weldnumbeValue + " and jointnumber= " + jointnumberValue + "", cn);

SqlDataAdapter ad = new SqlDataAdapter(Comm1);
DataSet ds = new DataSet();
ad.Fill(ds);
string str = string.Empty;
if (ds.Tables.Count > 1)
{
if (ds.Tables[0].Rows.Count > 1)
{
str = "Vales are Available!Enter it.";
}
}
else
{
str = "Vales are already exists!Please Choose another value.";
}
}


This above coding is correct or any changes is available.Kindly tell me the correct code.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100