Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

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.
 
Share this answer
 
Create one method to check record exists
C#
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

C#
if(!IsRecordExists(1,1))
{
//Data insert code
}
else
{
//Error:Data already available
}
 
Share this answer
 
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.";
}
}

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900