> "John Vinson" wrote...
An Access Table HAS NO ORDER - and a Query has no controlled order
either, unless you include an Order By clause. If you truly want a
random order (which, in this case, will be independent of the order of
arguments in the IN clause) use
SELECT id FROM mytable WHERE id IN(12, 14, 20, 21)
ORDER BY Rnd([ID]);
Hi John,
Your query works fast and accurate when I use it in MS Access (changed
it a little to my own needs).
The weird thing is, when I use the same query to fill a DataGrid (C#
WinForm) I get the same result every time.
For example: "SELECT TOP 8 id, latijn, nederlands FROM lexicon WHERE
datum>=1/1/2004 ORDER BY Rnd([id]);" returns a different result in
Access almost each time it is run. Filling a DataGrid on a Windows
Form results in the same order every time, although using the same
query.
I don't understand :o
************************
** Start Code Snippet **
************************
sqlSelect = "SELECT TOP 8 id, latijn, nederlands FROM lexicon WHERE
datum >= 1/1/2004 ORDER BY Rnd([id])";
OleDbCommand cmd = new OleDbCommand(sqlSelect, conn);
OleDbDataAdapter da2 = new OleDbDataAdapter(cmd.CommandText);
da2.SelectCommand = cmd;
DataTable dt = new DataTable("opvraging");
// try filling the DataTable
try {da2.Fill(dt);}
catch (OleDbException olex) {frm.ShowError(olex.Message); return; }
// adapt columns
dt.Columns[0].ColumnMapping = MappingType.Hidden; // do not show id
column
dt.Columns[1].ReadOnly = true;
dt.Columns[2].ColumnMapping = MappingType.Hidden; // do not show
translation
DataColumn vertaalKolom = new DataColumn("vertaling", typeof(String));
vertaalKolom.DefaultValue = "";
dt.Columns.Add(vertaalKolom);
// do not allow new rows or deleting rows
DataView dv = new DataView(dt);
dv.AllowDelete = false;
dv.AllowNew = false;
// fill datagrid
dg.DataSource = dv;
**********************
** End Code Snippet **
**********************
Regards,
Frederik