Link to home
Start Free TrialLog in
Avatar of Murray Brown
Murray BrownFlag for United Kingdom of Great Britain and Northern Ireland

asked on

ASP.net GridView not populating

Hi
I am using the following code to try and populate a GridView in ASP.net but nothing is coming through. I pretty much copied most of it from a VB.net Windows Form application where it retrieved the data fine. Is it perhaps my syntax?

hanks

    Sub DisplayContacts()
        Dim sqlConn As New SqlClient.SqlConnection
        sqlConn.ConnectionString = ConfigurationManager.ConnectionStrings("GHBCRM_TSTConnectionString").ConnectionString

        Try
            sqlConn.Open()
        Catch ex As Exception
            MsgBox(ex.Message, "connection failed")
        End Try

        Dim sqlComm As New SqlClient.SqlCommand
        sqlComm.Connection = sqlConn
        sqlComm.CommandType = CommandType.StoredProcedure

        sqlComm.CommandText = "spViewContacts"
        'sqlComm.CommandText = "spViewInvestorsInInvestments"

        strView = "All Contacts"
        sqlComm.Parameters.AddWithValue("@View", strView)
        sqlComm.Parameters.AddWithValue("@RM", strUserName)
        sqlComm.Parameters.AddWithValue("@Search", "")

        sqlComm.ExecuteNonQuery()

        da.SelectCommand = sqlComm
 

        Try
            If ds.Tables.IndexOf("tblContacts") > -1 Then
                ds.Tables("tblContacts").Clear()
            End If

            da.Fill(ds, "tblContacts")

            GridView1.DataSource = ds
            GridView1.DataMember = "tblContacts"
            'GridView1.Columns("contactid").Visible = False
            'GridView1.Columns(8).Visible = False

            'DisplayContactNotes(-1) 'Clear notes datagridview

            'lblStatus.Text = ds.Tables("tblContacts").Rows.Count.ToString & " Items"

        Catch

        End Try

        sqlConn.Close()

    End Sub
Avatar of evanburen
evanburen
Flag of United States of America image

Where are you declaring the variable strView?
What is the error you are getting?
Avatar of Murray Brown

ASKER

I'm declaring it at the top of the page. I am getting no error
It's hard to tell without seeing all of the code.  I don't see where you are creating your dataset (ds).  I would add debug="true" in your page declaration and check SQL Profiler to see what parameter values are being passed to your database.
ASKER CERTIFIED SOLUTION
Avatar of gery128
gery128
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks, that worked