Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Do While Seek()... Enddo
Message
De
13/01/2007 14:58:33
 
 
À
13/01/2007 13:00:20
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
01184819
Message ID:
01185384
Vues:
21
Wow, Cetin.
Thanks. I'm gonna have to pull an all nighter to comb through your example.:)

Thanks again.



>Sam,
>Probably
>
>myDataView.Sort = "cust_id";
>myDataView.Find("10001");
>
>is closest to your question genrally. There are also Filter and Select methods that you might utilize. New to 2.0 there is also Readder support for in memory tables. If you need a readonly, fast forward (scan...endscan style) thing then think of DataTablereader.
>
>However since you're after a 'seek' that uses a primary key column(s) then .Net has a more powerfull 'seek':
>
>myDataTable.Rows.Find( object )
>myDataTable.Rows.Find( object[] )
>
>ie:
>
>
>using System;
>using System.Data;
>using System.Data.OleDb;
>
>namespace SeekTest
>{
>    class Program
>    {
>        static void Main()
>        {
>            DataTable myDataTable = GetMyData();
>            DataRow seekRow;
>            myDataTable.CaseSensitive = false;
>
>            seekRow = mySeek(myDataTable, "cust_id", "ANATR");
>            if (seekRow != null)
>            {
>                Console.WriteLine(seekRow["company"]);
>            }
>            if (myDataTable.Rows.Contains("bonap"))
>            {
>                Console.WriteLine("BONAP exists. Contact is:{0}",
>                         myDataTable.Rows.Find("bonap")["Contact"]);
>            }
>
>            seekRow = mySeek(myDataTable,
>               new string[] { "company", "country" },
>               new object[] { "The Cracker Box", "USA" });
>            if (seekRow != null)
>            {
>                Console.WriteLine("{0},{1},{2}",
>                  seekRow["company"],
>                  seekRow["cust_id"],
>                  seekRow["country"]);
>            }
>        }
>
>        static DataRow mySeek(DataTable dt, string searchColumn, object valueToSearch)
>        {
>            dt.PrimaryKey = new DataColumn[] { dt.Columns[searchColumn] };
>            return dt.Rows.Find(valueToSearch);
>        }
>
>        static DataRow mySeek(DataTable dt, string[] searchColumns, object[] valuesToSearch)
>        {
>            DataColumn[] keys = new DataColumn[searchColumns.Length];
>            for (int i = 0; i < searchColumns.Length; i++)
>            {
>                keys[i] = dt.Columns[searchColumns[i]];
>            }
>            dt.PrimaryKey = keys;
>            return dt.Rows.Find(valuesToSearch);
>        }
>
>        static DataTable GetMyData()
>        {
>            string strConn = @"Provider=VFPOLEDB;Data source=
>C:\Program Files\Microsoft Visual FoxPro 9\Samples\Data\testdata.dbc;";
>            string strQuery = "select * from customer";
>            DataTable dt = new DataTable();
>
>            using (OleDbConnection cn = new OleDbConnection(strConn))
>            {
>                cn.Open();
>                OleDbCommand cmd = new OleDbCommand(strQuery, cn);
>                OleDbDataReader rdr = cmd.ExecuteReader();
>                dt.Load(rdr);
>                rdr.Close();
>            }
>            return dt;
>        }
>    }
>}
>
>Cetin
>
>
>
>
>
>>Hi Einar.
>>I've been trying to find how to SEEK my DataView, but I could'nt find a way. So I did this.
>>
>>
>> SrcDataAdapter.Fill(SrcDataSet,"customer");
>>
>> DataView myDataView = new DataView(SrcDataSet.Tables[0]);
>>
>> myDataView.RowFilter = "cust_id = '10001'";
>>
>> int ncnt = myDataView.Count;
>>
>>
>>
>>I know it's probably not the best thing, but it works.
>>
>>How do I create an index on my DataView to do a SEEK() on it?
>>
>>TIA.
>>
>>
>>>>Is there an simple elegant way to do the following in C#?
>>>>
>>>>
>>>>i=1
>>>>DO WHILE SEEK(i, 'testTbl', 'testInx')
>>>>    i = i + 1
>>>>ENDDO
>>>>
>>>>RETURN i
>>>>
>>>>
>>>>TIA
>>>
>>>
>>>private int fubar()
>>>{
>>>	int i = 1;
>>>	while (SEEK(i, "testTbl", "testInx"))
>>>	{
>>>		i++;
>>>	}
>>>	return i;
>>>}
>>>
The American Republic will endure, until politicians realize they can bribe the people with their own money.
- Alexis de Tocqueville

No man’s life, liberty, or property is safe while the legislature is in session.
– Mark Twain (1866)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform