VB.Net Datagrid

A

Allen

Is there a way to bind a datagrid in VB.Net to an ADODB Recordset object? I
have tried:

rs.Open ("SELECT Name FROM tblStaff",connection)

dgTest.SetDataBindings(rs,"")

The recordset is filled but it returns an error at the datagrid
databinding.

TIA :)
--
ats@home

When an old lady got hit by a truck
I saw a wicked gleam in your eye

Handy utils here: http://www.allenjones.co.uk/utils.htm
 
A

Armin Zingler

A

Allen

The documentation of the Datagrid.datasource property lists the variety of
supported data sources.

I have read some of it and from this know that it can be bound to an ADODB
recordset. However, it is the second parameter that is causing the error.
The documentation says that the default is an empty string but it fails. I
have also tried putting the table name in there but that generates an error
saying that a Child record cannot be crteated for the table. What should be
put into the second parameter?
--
ats@home

When an old lady got hit by a truck
I saw a wicked gleam in your eye

Handy utils here: http://www.allenjones.co.uk/utils.htm
 
S

Shirish Kokate

Data source must implement the 'IEnumerable' interface
like DataTable, DataView, ArrayList, Hashtable but not
the Recordset. First fill DataTable from Recordset and
then bind DataTable to DataGrid.

Try this code:
Dim custDA As New OleDbDataAdapter
Dim dtTerritories As New DataTable
Dim Conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim dgTest as New dataSet

Conn.Open("<-----Use Connection String------
";", "", "", -1)
RS.Open("SELECT Name FROM tblStaff", Conn,
ADODB.CursorTypeEnum.adOpenForwardOnly,
ADODB.LockTypeEnum.adLockReadOnly, 1)

custDA.Fill(dtTerritories, RS)
RS.Close()
Conn.Close()
RS = null
Conn = null
dgTest.DataSource = dtTerritories
dgTest.DataBind()

Also, you make like to Reference traditional DataGrid of
VB 6.0 in Windows Form application. Traditional DataGrid
of VB 6.0 may not work in web application.

Good Luck
 
C

Cor Ligthert

Allen,

You can using the dataadapter make a dataset from a recordset.

I is
datadapter.fill(dataset,recordset,"mytable")

However it has less sence because it is only usable for filling the grid,
not for writing back to the recordset.

When you are able to that take the ADONET approach, which is much easier by
the way too.

Cor
 
A

Allen

Data source must implement the 'IEnumerable' interface
like DataTable, DataView, ArrayList, Hashtable but not
the Recordset. First fill DataTable from Recordset and
then bind DataTable to DataGrid.

Try this code:
Dim custDA As New OleDbDataAdapter
Dim dtTerritories As New DataTable
Dim Conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim dgTest as New dataSet

Conn.Open("<-----Use Connection String------
RS.Open("SELECT Name FROM tblStaff", Conn,
ADODB.CursorTypeEnum.adOpenForwardOnly,
ADODB.LockTypeEnum.adLockReadOnly, 1)

custDA.Fill(dtTerritories, RS)
RS.Close()
Conn.Close()
RS = null
Conn = null
dgTest.DataSource = dtTerritories
dgTest.DataBind()

Also, you make like to Reference traditional DataGrid of
VB 6.0 in Windows Form application. Traditional DataGrid
of VB 6.0 may not work in web application.

Good Luck

Thanks for that. I will give it a whirl when I get to work :)

--
ats@home

When an old lady got hit by a truck
I saw a wicked gleam in your eye

Handy utils here: http://www.allenjones.co.uk/utils.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Email Archive program 12
Last Friday of each month 3
int.TryParse 9
Server.MapPath 3
ADO connection err. in ASP but not in VB.net 1

Top