OledbReader question  
Author Message
EShepley





PostPosted: .NET Framework Data Access and Storage, OledbReader question Top

How do I use the OledbReader to insert string data into either a variable or textbox to be displayed on a form

.NET Development24  
 
 
Matt Neerincx





PostPosted: .NET Framework Data Access and Storage, OledbReader question Top

Here is a quick example to just go to the first record of customers table and read value:


OleDbCommand cmd = new OleDbCommand();

try
{
conn.Open();
cmd.Connection = conn;
cmd.CommandText = "select * from customers";
using (OleDbDataReader dr = cmd.ExecuteReader())
{
// Skip to first record.
dr.Read();
// Read first column (Customer ID).
textBox1.Text = dr.GetString(0);
}
}
catch (OleDbException oledbEx)
{
System.Diagnostics.Debug.WriteLine("oledbEx.Message=" + oledbEx.Message);
if (null != oledbEx.InnerException)
{
System.Diagnostics.Debug.WriteLine("oledbEx.InnerException.Message=" + oledbEx.InnerException.Message);
}
}
conn.Close();



 
 
EShepley





PostPosted: .NET Framework Data Access and Storage, OledbReader question Top

Can't seem to get it too work, there is data in the table yet it keeps coming up with "No data exists for the row/column"

My code looks like this

cmdSearch = New OleDbCommand( , conSearch)

cmdSearch.Parameters.AddWithValue( , strDate)

cmdSearch.Parameters.AddWithValue( , strTime)

conSearch.Open()

Dim dr As OleDbDataReader = cmdSearch.ExecuteReader()

dr.Read()

txtName.Text = dr.GetString(0)

conSearch.Close()

Where am I going wrong


 
 
Bappi





PostPosted: .NET Framework Data Access and Storage, OledbReader question Top

Can u please check the sql statement

agaisnt your database with the value u r giving from ur code.

Check whether its returning u any data.



 
 
Miha Markic





PostPosted: .NET Framework Data Access and Storage, OledbReader question Top

Some advices:

First, check out what value returns Read() method.

Then you might replace parameter names in sql statement with question marks ( ), like:

SELECT * FROM tblBooking WHERE Booking_Date = AND Booking_Time =

Next, check whether same statement works within access.



 
 
EShepley





PostPosted: .NET Framework Data Access and Storage, OledbReader question Top

Thanks for all of the help guys, managed to solve the problem