connect a Query to a DBGrid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Sounds a real begin question, but anyway I could not find it. I can make a
query like this example where some data come in a listbox. But now I have to
display in datagrid. Can someone advice me here ?

OleDbCommand SQL = new OleDbCommand("SELECT * FROM LastPos",
Main.DBConnection);
Main.DBConnection.Open();
OleDbDataReader Reader = SQL.ExecuteReader();
listBox.Items.Clear();
try {
while (Reader.Read()) {
 
Hi,

I found something, but it does not work :(

try {
Main.DBConnection.Open();
try {
OleDbDataAdapter Adapter = new OleDbDataAdapter("SELECT
* FROM Rx", Main.DBConnection);
DataSet ds = new DataSet();
Adapter.Fill(ds);
dataGrid.DataSource = ds;
ds.WriteXml("c:\\111.xml");
} finally {
Main.DBConnection.Close();

The Grid is just empty :(
the dataset is filled, because the xml file contain all data (this is only
to debug my code). What do I do wrong here ?
 
Found it :)
Seems there has to be a TableName and a DataMember:

ds.Tables[0].TableName = "Rx";
dataGrid.DataMember = "Rx";

rgds, Wilfried
 
found it :)
Seems to be there has to be a TableName assigned and a DataMember:

ds.Tables[0].TableName = "Rx";
dataGrid.DataMember = "Rx";

rgds, Wilfried
 
found it :)
Seems to be there has to be a TableName assigned and a DataMember:

ds.Tables[0].TableName = "Rx";
dataGrid.DataMember = "Rx";

rgds, Wilfried
 
found it :)
Seems to be there has to be a TableName assigned and a DataMember:

ds.Tables[0].TableName = "Rx";
dataGrid.DataMember = "Rx";

rgds, Wilfried
 
Found it :)
Seems there has to be assigned a TableName and a DataMember. This is the
complete working code:

Main.DBConnection.Open();
try {
OleDbDataAdapter Adapter = new OleDbDataAdapter("SELECT
* FROM Rx", Main.DBConnection);
DataSet ds = new DataSet();
Adapter.Fill(ds);
dataGrid.DataSource = ds;
ds.Tables[0].TableName = "Rx";
dataGrid.DataMember = "Rx";
} finally {
Main.DBConnection.Close();
}

rgds, Wilfried
 
Back
Top