比较一个数据表中的两列值 [英] compare two columns values in one data table
问题描述
亲爱的所有人,
这是我的桌子
rtnumber焊接编号jointnumber焊接编号
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 这次我想显示错误消息框,此数据已可用.
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-1 这一次我想显示错误消息,此数据已可用.
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-2 这一次我想显示错误消息框,此数据已可用.
我的问题:
当我第一次将数据添加到数据表中时,它将插入(1,1,1-1),相同的现有数据(1,1,1-1),当我将第二次添加时,这一次我想显示基于错误消息在焊接编号和接头编号列上.
有人可以帮助我.
ragards
samy
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
推荐答案
创建一种方法来检查记录是否存在
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
}
私有布尔值IsRecordExists(int weldnumberValue,int jointnumberValue)
{
SqlConnection cn =新的SqlConnection(ConfigurationManager.AppSettings ["Connection"]);
SqlCommand Comm1 =新的SqlCommand(从mytable中选择rtnumber,其中weldnumber ="+ weldnumbeValue +"和jointnumber =" + jointnumberValue +",cn);
SqlDataAdapter广告=新的SqlDataAdapter(Comm1);
DataSet ds = new DataSet();
ad.Fill(ds);
字符串str = string.Empty;
如果(ds.Tables.Count> 1)
{
如果(ds.Tables [0] .Rows.Count> 1)
{
str =可用值!请输入.";
}
}
其他
{
str =值已经存在!请选择另一个值.";
}
}
上面的代码正确无误或有任何可用的更改.请告诉我正确的代码.
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.
这篇关于比较一个数据表中的两列值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!