Solved

ASP.net GridView not populating

Posted on 2012-03-23
6
303 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
[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:murbro
ID: 37756958
I'm declaring it at the top of the page. I am getting no error
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 

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

Independent Software Vendors: 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!

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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