Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

binding data to a datagrid 1

Status
Not open for further replies.

ds2728

Programmer
Jul 18, 2001
50
0
0
US
Hello, I need help:

I have 2 forms, the first one called frmMain, and the second one frmFilesList. frmMain is the main form and I have a menu option to select that opens the second form.

On the second form I have a datagrid that is supposed to display a list of records I have in a recordset.

My problem is my second form opens with my datagrid displayed with all 7 columns with the header text displayed. BUT with no data.

I can't figure out why I have no data in my datagrid, any help would be greatly appreciated.

Here is my code which actually resides in frmMain.vb under the sub "...click" :

Private Sub tsmiInteractive_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles tsmiInteractive.Click

Dim fFilesList As New frmfilesList

ConnectToDBs() 'make connection see *** below for
actual connection string

Dim rs As ADODB.Recordset
Dim strsql As String


mDBriskmaster_bankingConnection.CursorLocation = ADODB.CursorLocationEnum.adUseClient

fFilesList.Text = "Interactive Mode"
fFilesList.Icon = New Icon(Me.GetType(), "RunSpecific.ico")

strsql = "Select * from mandtfiles"

rs = New ADODB.Recordset
rs.Open(strsql, mDBriskmaster_bankingConnection, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockOptimistic)

With fFilesList.DGVfiles 'DGVfiles is the name for the datagrid
.Columns.Add("column1", "column one")
.Columns.Add("column2", "column two")
.Columns.Add("column3", "column three")
.Columns.Add("column4", "column four")
.Columns.Add("column5", "column five")
.Columns.Add("column6", "column six")
.Columns.Add("column7", "column seven")

.Columns("column1").DataPropertyName = "filestatus"
.Columns("column2").DataPropertyName = "loaddate"
.Columns("column3").DataPropertyName = "reportedreccnt"
.Columns("column4").DataPropertyName = "reportedrecamt"
.Columns("column5").DataPropertyName = "actualreccnt"
.Columns("column6").DataPropertyName = "actualrecamt"
.Columns("column7").DataPropertyName = "fileid"
End With

fFilesList.DGVfiles.DataSource = rs


fFilesList.ShowDialog()

End Sub


**** DRIVER=SQL Server;SERVER=psba-trustsql;
DATABASE=riskmaster_banking;UID=xxxxxx;
Trusted_connection=Yes

when in debug mode I can see that I do have 2 records in my recordset, and can also see the data in each record.

Thanks in advance for your help.

Dave
 
Read this page:


The DataGridView class supports the standard Windows Forms data-binding model. This means the data source can be of any type that implements one of the following interfaces:

* The IList interface, including one-dimensional arrays.
* The IListSource interface, such as the DataTable and DataSet classes.
* The IBindingList interface, such as the BindingList<(Of <(T>)>) class.
* The IBindingListView interface, such as the BindingSource class.

Since ADODB.Recordset doesn't implement one of those interfaces, you might as well just code it to ADO.Net and DataSets and be done with it. Here's a rough translation of your code, untested:

Code:
Private Sub tsmiInteractive_Click(ByVal sender As
            System.Object, ByVal e As System.EventArgs)
            Handles tsmiInteractive.Click

        Dim fFilesList As New frmfilesList

        ConnectToDBs() 'make connection  see *** below for
                        actual connection string

        'Dim rs As ADODB.Recordset
        Dim dt As DataTable
        Dim da As SqlClient.SqlDataAdapter
        Dim cmd As SqlClient.SqlCommand
        Dim con As New SqlClient.SqlConnection("some connection string")	
        Dim strsql As String


        mDBriskmaster_bankingConnection.CursorLocation = ADODB.CursorLocationEnum.adUseClient

        fFilesList.Text = "Interactive Mode"
        fFilesList.Icon = New Icon(Me.GetType(), "RunSpecific.ico")

        strsql = "Select * from mandtfiles"

        'rs = New ADODB.Recordset
        'rs.Open(strsql, mDBriskmaster_bankingConnection, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockOptimistic)
        dt = New DataTable
        cmd = New SqlClient.SqlCommand
        cmd.Connection = con
        cmd.CommandType = CommandType.Text
        cmd.CommandText = strsql
        da = New SqlClient.SqlDataAdapter	
        da.SelectCommand = cmd
        da.Fill(dt)


        With fFilesList.DGVfiles      'DGVfiles is the name for the datagrid
            .Columns.Add("column1", "column one")
            .Columns.Add("column2", "column two")
            .Columns.Add("column3", "column three")
            .Columns.Add("column4", "column four")
            .Columns.Add("column5", "column five")
            .Columns.Add("column6", "column six")
            .Columns.Add("column7", "column seven")

            .Columns("column1").DataPropertyName = "filestatus"
            .Columns("column2").DataPropertyName = "loaddate"
            .Columns("column3").DataPropertyName = "reportedreccnt"
            .Columns("column4").DataPropertyName = "reportedrecamt"
            .Columns("column5").DataPropertyName = "actualreccnt"
            .Columns("column6").DataPropertyName = "actualrecamt"
            .Columns("column7").DataPropertyName = "fileid"
        End With

        fFilesList.DGVfiles.DataSource = dt


        fFilesList.ShowDialog()

    End Sub
 
RiverGuy,

Thanks for your help, it worked great.

I am new to vb.net and still having troubles with the whole concept transferring my vba knowledge. Although my son is knows both vb.net and now is working in java, is a great encourager for me to figure this vb.net stuff out.

Thanks again,

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top