Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 ASP.NET
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 25-Nov-12 21:09pm
samy555646
Rate this: bad
good
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
}
  Permalink  
Comments
samy555 at 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 at 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: bad
good
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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 130
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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