Solved

ASP.net GridView not populating

Posted on 2012-03-23
6
297 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
ID: 37756906
Where are you declaring the variable strView?
0
 
LVL 1

Expert Comment

by:imranrizvi
ID: 37756914
What is the error you are getting?
0
 

Author Comment

by:murbro
ID: 37756958
I'm declaring it at the top of the page. I am getting no error
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Expert Comment

by:evanburen
ID: 37757004
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
ID: 37757020
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
ID: 37763086
thanks, that worked
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 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

14 Experts available now in Live!

Get 1:1 Help Now