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!

Need help filling datagridview from stored procedure which fills data reader

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
0
36
US
VB.NET 2010
I used this code in ASPNET 4.0 page with success. But now in the Desktop world not sure how to bind it?
If I take out the Me.DataGridView1.DataBindings line, I do not get an error but the grid is empty.
I takes a while to run so I am sure its filling the reader.

TIA

Code:
        Dim cnn As SqlConnection
        Dim cmd As New SqlCommand
        Dim Retval As String = ""
        Dim connStr As String = gblConnectionString
        cnn = New SqlConnection(connStr)
        Try
            cnn.Open()
            With cmd
                .Connection = cnn
                 .CommandText = "uspGetLdapHierarchyByTopEid"
                .CommandType = CommandType.StoredProcedure
                .Parameters.AddWithValue("sTopEid", Me.cboChooseEnterpriseID.Text)
                .Parameters(0).SqlDbType = SqlDbType.NVarChar
                Me.DataGridView1.DataSource = .ExecuteReader() 
                Me.DataGridView1.DataBindings(  <<<<< ????
            End With
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

DougP
 
I found this which is very simple and works great.
I have a stored procedure and am just calling it with one parameter in a SQL string.

Code:
       Dim cn As New SqlClient.SqlConnection
        cn.ConnectionString = gblConnectionString
        Dim strSQL As String = "EXEC uspGetLdapHierarchyByTopEid " & Me.cboChooseEnterpriseID.Text & ";"
        Dim strCon As String = gblConnectionString
        Dim dataAdapter As New SqlClient.SqlDataAdapter(strSQL, strCon)
        Dim table As New DataTable
        dataAdapter.Fill(table)
        DataGridView1.DataSource = table

DougP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top