472,141 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,141 software developers and data experts.

ODBC.net

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);

}

}

************************************************** *************
Nov 15 '05 #1
3 2146
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...


"Travis" <tr********@hotmail.com> wrote in message
news:eT**************@TK2MSFTNGP11.phx.gbl...
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);

}

}

************************************************** *************

Nov 15 '05 #2

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
-----Original Message-----
OK Sorry all I used
System.Diagnostics.Debug.WriteLine()

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


"Travis" <tr********@hotmail.com> wrote in message
news:eT**************@TK2MSFTNGP11.phx.gbl...
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 byConnector/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 yourcode
again or did you miss a field...",

MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

}

}

************************************************** *********
****

.

Nov 15 '05 #3
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...

"Richard" <an*******@discussions.microsoft.com> wrote in message
news:70****************************@phx.gbl...

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
-----Original Message-----
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...


"Travis" <tr********@hotmail.com> wrote in message
news:eT**************@TK2MSFTNGP11.phx.gbl...
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);

}

}

************************************************** *********
****

.

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Marco Aschwanden | last post: by
4 posts views Thread by Andreas Lauffer | last post: by
3 posts views Thread by Lauren Quantrell | last post: by
5 posts views Thread by Alec | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.