不重複比對演算法

不重複比對演算法

http://ocean2002n.pixnet.net/blog/post/86881076-%5B%E6%95%99%E5%AD%B8%5D-%E4%B8%8D%E9%87%8D%E8%A4%87%E6%AF%94%E5%B0%8D%E6%BC%94%E7%AE%97%E6%B3%95

 

 

string strConn = "", strUserID = "", strUserName = "";

strConn = ConfigurationManager.AppSettings["strConn"];

SqlConnection ObjConn = new SqlConnection(strConn);

SqlDataAdapter ObjCmd = new SqlDataAdapter("select UserID from RegInfo where TeamName='" + txtTeamName.Text.Trim() + "' ", ObjConn);

DataSet ObjDS = new DataSet();

ObjCmd.Fill(ObjDS, "RegInfo");

for (int i = 0; i < ObjDS.Tables["RegInfo"].Rows.Count; i++)

{

    strUserID = ObjDS.Tables["RegInfo"].Rows[i]["UserID"].ToString();//資料一筆一筆存入StrUserID

 

    if(strUserName!="")

    {

        //資料一筆一筆比對

        strUserName = strUserName +"\\n"+ objFun.GetValues("select UserName from UserInfo where ID='" + strUserID + "'", "UserName");

    }

    else

    {

        //資料一筆一筆比對

        strUserName = objFun.GetValues("select UserName from UserInfo where ID='" + strUserID + "'", "UserName");

    }

}

ObjConn.Dispose();

ObjCmd.Dispose();

ObjDS.Dispose();

------------------------------------------------------------------

int flag;
foreach (System.Data.DataRow row1 in dtV1.Rows)
{
       flag=0;
        foreach (System.Data.DataRow row2 in dtV2.Rows)
        {
           if (row1.Equals(row2))
           flag=1;
           break;
        }
       if (flag==0)
       //do something
}

最笨的方法....NxN比對.....