ODBC.net

T

Travis

I am trying to display a query like this in my windows form:


SELECT workordernumber, date, firstname, lastname FROM customer_db;

I am using a rich text box to display the data but it only displays ONE
record in the rich text box. How do you display all the found records.

I am using the System.Data.Odbc;
it is quite easy to use, but I cannot figure out how to display large
amounts of data to a form



Here is the code for the button I use to do the Query Result
***************************************************************
private void QueryButton_Click(object sender, System.EventArgs e)

{

string mySelectQuery = "SELECT workordernumber, date, firstname, lastname
FROM customers;

OdbcCommand myCommand = new OdbcCommand(mySelectQuery,myConnection);

myConnection.Open();

try

{

myDataReader = myCommand.ExecuteReader();

while (myDataReader.Read())

{

if (string.Compare (myConnection.Driver,"myodbc3.dll") == 0 )

{

QueryResultsRichTextBox.Text = ("Data:\nWO#: Date: Firstname Lastname:\n" +
myDataReader.GetString(0) + " " + myDataReader.GetString(1) + " " +
myDataReader.GetString(2) + " " myDataReader.GetString(3)

);

//+ " " + MyOtherDataReader.GetInt64(2)); //Supported only by Connector/ODBC
3.51

}

else

{

QueryResultsRichTextBox.Text = ("Data:" + myDataReader.GetInt32(0) + " " +

myDataReader.GetString(1) + " " +

myDataReader.GetInt32(2)); //BIGINTs not supported by Connector/ODBC

}


}

//Close all resources

myDataReader.Close();

myConnection.Close();

}

catch

{

MessageBox.Show ("An error has occured in your query", "Look over your code
again or did you miss a field...",

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}

}

***************************************************************
 
T

Travis

OK Sorry all I used
System.Diagnostics.Debug.WriteLine()

and it displayed all my query results, how can I get that into a nice format
or window for displaying...
 
R

Richard

If you just want a dump of your data you can load the
columns of your DataReader into a listview... However...

If you're going to do any serious DB work in .NET {forms,
ASP, modifying data} you need to take the time to learn
how ADO.NET is put together. ADO.NET is a big topic but
crunched down to a couple of sentences to give you some
keywords:

1) DBConnections log you on and off of databases.

2) DataAdapters know the specific dialect of your
database: Oracle, Access, SQL Server etc. Adapters know
about connections and they have the SQL for four basic
operations: select, insert, update, delete.

3) DataTables are loaded with data from DataAdapters
during a "Fill". Changes in DataTables are applied to
databases via the DataAdapter during an "Update".
DataTables live in DataSets.

3) DataSets are in memory databases that contain
DataTables to hold data and DataRelations to enforce
constraints and relationships between tables.

4) .NET GUI controls use "Data Binding" to connect their
displayed value to data in DataSets. Some controls can
bind to many rows of data at a time {grids} and other
controls typically bind to a single column and one row of
data at a time {textboxes}. GUI controls
use "BindingContexts" to synchronize with each other and
allow many controls, possibly on many forms, to navigate
and edit data with amazingly little source code written by
hand. :)

--Richard
 
T

Travis

How exactly do you dump your data into a listview??? I can find no examples
of how to do this using the ODBC.net DataReaderClass, everything is SQLClass
stuff...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top