By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,680 Members | 1,578 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,680 IT Pros & Developers. It's quick & easy.

ODBC.net

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a

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

P: n/a
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.