情况是这样滴,关于彩票的数字对比问题,有一个数据表,其中存储着red1,red2,red3,red4,red5,red6,blue和term几个数据字段,都为整型。现在窗口上有七个textbox,当用户往里输入自己所想要的彩票号码后,按下“对比”batton,将在下面的lable中返回用用户输入号码与数据库中存储的彩票号码最为匹配的一期彩票号码,应该怎么做?
   小女菜鸟一名,望求各位高人解答~~~

解决方案 »

  1.   

    batton事件。连接数据库搜索数据库中的内容与输入的做对比,这是最基本的ADO.NET的练习。如果还不会,等下我把代码给你写出来
      

  2.   


    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 "这个最匹配有点难搞.....
      

  3.   

    根据你自己的条件(根据text中的文本),去数据库查就是了
      

  4.   

    匹配多个字段无非就是多个and or的组合,究竟哪个最匹配,那你还要加上你自己的匹配算法才行
      

  5.   

    先把数据库中的所有数据取到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++;
          
        }
     }
     if(iMatch>iMaxMatch)
      
        iRowIndex=i;
    }
      

  6.   

    可是用and和or组合会太长了啊,比如说用户输入的一期彩票号码是“10,07,21,33,15,26,02”不一定是有序排列,然后与数据库中的N多期彩票中奖号码进行对比,那就得用每个数值与数据库中每一列对比,并且记匹配数,从而才能找到最匹配的一项啊。
      

  7.   

    上面的少了一行
    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;
      }
    }
      

  8.   

    又发现少写两行。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++;
          i++;
          j++;
        }
     }
     if(iMatch>iMaxMatch)
      {
        iMaxMatch=iMatch;
        iRowIndex=i;
      }
    }
      

  9.   

    我给你写出了大体的代码:
    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的基础,你可以看下这方面的书
      

  10.   

    刚才没看你评论中的要求,那我写的就不合适了,我看了下11楼 fengjian_428写的是正解,你可以参考下。
    有问题再继续讨论!
      

  11.   

    非常不好意思,这么晚才给分,因为有事给耽搁了。
    fengjian_428 谢谢~~
    sushou2009 虽然你误解了意思,不过很热心,谢谢~~~给你们加分了~