[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

ASP.net GridView not populating

Posted on 2012-03-23
6
Medium Priority
?
305 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:Murray Brown
ID: 37756958
I'm declaring it at the top of the page. I am getting no error
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 2000 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:Murray Brown
ID: 37763086
thanks, that worked
0

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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 video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

649 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