Datareader Problem

jeva39

Well-known member
Joined
Jan 28, 2005
Messages
135
Location
Panama
Programming Experience
1-3
This code don't work. Please, what is wrong?

VB.NET:
Private Sub Prueba_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
	Dim con As OleDbConnection
	Dim cmd As OleDbCommand
	Dim reader As OleDbDataReader
	Me.con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "\caritas.mdb"
	con.Open()
	cmd = New OleDbCommand("Select * from  Prestamo order by nombre", con)
	reader = cmd.ExecuteReader()
	myGrid.DataSource = reader
	myGrid.DataBind()
	con.Close()
End Sub
 
Try this, it works

I think this will accomplish what you are trying to do.
--------------------------------------------------------------



cn = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "\caritas.mdb")


Dim ds As System.Data.DataSet = New System.Data.DataSet("Result")

Dim da As System.Data.OleDb.OleDbDataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQL, cn)

da.Fill(ds)

myGrid.DataSource = ds

 
Thanks. Your code is OK and I am used DataSets in many routines in the actual application but, for a special case, I need to use a DataReader with a DataGrid but the code above (really it is valid) always generate an error and I don't now what is the cause. Again, thanks!!!
 
Back
Top