string str1 as string=textbox1.text.trim.tostring(); string str2 as string=textbox2.text.trim.tostring(); string str3 as string=textbox3.text.trim.tostring(); string str4 as string=textbox4.text.trim.tostring(); string str5 as string=textbox5.text.trim.tostring(); string str6 as string=textbox6.text.trim.tostring(); string str7 as string=textbox7.text.trim.tostring();string stra=str1+str2+str3+str4+str5+str6+str7;string strb=stra.replace(" ","") string sql="select * from table where 号码 >='"+ strb+"' order by 号码 desc "这个最匹配有点难搞.....
根据你自己的条件(根据text中的文本),去数据库查就是了
匹配多个字段无非就是多个and or的组合,究竟哪个最匹配,那你还要加上你自己的匹配算法才行
先把数据库中的所有数据取到datatable dt里面 textbox里面的值从小到大放进int[] iVsint iMaxMatch=0; //存储当前最大匹配次数 int iRowIndex; //最大匹配数据的行数 for(int i=0;i<dt.Rows.count;i++) { int k=0; int j=0; int iMatch=0; while(k<iVs.length&&j<dt.Rows.Cells.count) { if(iVs[k]<Convert.ToInt32(dt.Rows[i][j])) { k++; } else if(iVs[k]>Convert.ToInt32(dt.Rows[i][j])) { j++; } else { iMatch++;
string str1 as string=textbox1.text.trim.tostring();
string str2 as string=textbox2.text.trim.tostring();
string str3 as string=textbox3.text.trim.tostring();
string str4 as string=textbox4.text.trim.tostring();
string str5 as string=textbox5.text.trim.tostring();
string str6 as string=textbox6.text.trim.tostring();
string str7 as string=textbox7.text.trim.tostring();string stra=str1+str2+str3+str4+str5+str6+str7;string strb=stra.replace(" ","")
string sql="select * from table where 号码 >='"+ strb+"' order by 号码 desc "这个最匹配有点难搞.....
int iRowIndex; //最大匹配数据的行数
for(int i=0;i<dt.Rows.count;i++)
{
int k=0;
int j=0;
int iMatch=0;
while(k<iVs.length&&j<dt.Rows.Cells.count)
{
if(iVs[k]<Convert.ToInt32(dt.Rows[i][j]))
{
k++;
}
else if(iVs[k]>Convert.ToInt32(dt.Rows[i][j]))
{
j++;
}
else
{
iMatch++;
}
}
if(iMatch>iMaxMatch)
iRowIndex=i;
}
int iMaxMatch=0; //存储当前最大匹配次数
int iRowIndex; //最大匹配数据的行数
for(int i=0;i<dt.Rows.count;i++)
{
int k=0;
int j=0;
int iMatch=0;
while(k<iVs.length&&j<dt.Rows.Cells.count)
{
if(iVs[k]<Convert.ToInt32(dt.Rows[i][j]))
{
k++;
}
else if(iVs[k]>Convert.ToInt32(dt.Rows[i][j]))
{
j++;
}
else
{
iMatch++;
}
}
if(iMatch>iMaxMatch)
{
iMaxMatch=iMatch;
iRowIndex=i;
}
}
int iRowIndex; //最大匹配数据的行数
for(int i=0;i<dt.Rows.count;i++)
{
int k=0;
int j=0;
int iMatch=0;
while(k<iVs.length&&j<dt.Rows.Cells.count)
{
if(iVs[k]<Convert.ToInt32(dt.Rows[i][j]))
{
k++;
}
else if(iVs[k]>Convert.ToInt32(dt.Rows[i][j]))
{
j++;
}
else
{
iMatch++;
i++;
j++;
}
}
if(iMatch>iMaxMatch)
{
iMaxMatch=iMatch;
iRowIndex=i;
}
}
private void button1_Click(object sender, EventArgs e)
{
int count = 0;
string strSql = "server =.;database = CaiPiao;integrated security=true";
SqlConnection scon = new SqlConnection();
scon.Open(); //打开数据库
string sql=string .Format ("select * from caipiao where red1={0} and red2={1} and red3={2}...",int.Parse(textBox1.Text.Trim()),int.Parse(textBox2.Text.Trim()),int .Parse(textBox3.Text.Trim()),....);
SqlCommand scom=new SqlCommand (sql,scon);
count = Convert .ToInt32(scom.ExecuteScalar());
if (count > 0)
{
MessageBox.Show ("全部一样");
}
else
{
MessageBox .Show ("不一样");
}
}你自己看下,这是ADO.NET的基础,你可以看下这方面的书
有问题再继续讨论!
fengjian_428 谢谢~~
sushou2009 虽然你误解了意思,不过很热心,谢谢~~~给你们加分了~