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