Solved

ASP.net GridView not populating

Posted on 2012-03-23
6
294 Views
Last Modified: 2012-03-25
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
0
Comment
Question by:murbro
6 Comments
 

Expert Comment

by:evanburen
Comment Utility
Where are you declaring the variable strView?
0
 
LVL 1

Expert Comment

by:imranrizvi
Comment Utility
What is the error you are getting?
0
 

Author Comment

by:murbro
Comment Utility
I'm declaring it at the top of the page. I am getting no error
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Expert Comment

by:evanburen
Comment Utility
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.
0
 
LVL 9

Accepted Solution

by:
gery128 earned 500 total points
Comment Utility
Where are you binding the grid ?
try putting this line
GridView1.DataBind() after this line
GridView1.DataMember = "tblContacts"
so your code would look like:
GridView1.DataSource = ds
GridView1.DataMember = "tblContacts"
GridView1.DataBind() 

Open in new window


Also can you check in debugging if you are getting some records in
ds.Tables("tblContacts")??
It may happen that you don't have records in tables.
0
 

Author Closing Comment

by:murbro
Comment Utility
thanks, that worked
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now