In VB6, ADO is available in database programming. In the new VB.NET, although it can also be used to query the database, in the binding of the new DataGrid, it is not possible to use it as before: "DataGrid1.datasoure = RS", but requires a certain conversion. Because the new DataGrid.DataSou is a DataTable or DataSet, it is not the original Recordset. So, in use, turn the RecordSet into a DataTable or DataSet. We take DataTable as an example:
Function RecordsetToDataTable (ByVal adoRS As ADODB.Recordset, ByVal strTable As String) adoRS.MoveFirst () Dim dt As DataTable dt = New DataTable (strTable) Dim i As Integer Dim strcolname As String Dim t As Type Dim dr As DataRow
For i = 0 to adors.fields.count - 1 strcolname = adors.fields (i) .name t = adors.fields (i) .Value.gettype () dt.columns.add (Strcolname, T) NEXT
While (NOT Adors.eof) DR = DT.NEWROW () for i = 0 to adors.fields.count - 1 DR (i) = adors.fields (i) .value next dt.Rows.Add (DR) Adors. MoveNext () end while
Return DT
END FUNCTION
The above function is to achieve recordset into DataTable
And what we have to do is to join the transformation of the ADO after adding the transformation in the window.
DIM DTS AS DataTable
DTS = RecordSetTodataTable (RSuser, "Login") 'where rsuse is ado.recordset, "login" is a table name DataGrid1.DataSource = dts.defaultview