7 Replies - 1157 Views - Last Post: 05 February 2017 - 11:41 AM Rate Topic: -----

#1 alanSmirnov   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 26-January 17

Gridview not outputting data

Posted 04 February 2017 - 04:28 PM

I am writing a times tables program in ASP.net and I need some help. The problem I am experiencing is that When i try and populate the gridview it doesn't even appear on the web form when ran. I have been researching for the past few hours but no luck.

Can anyone look at my code and see what the problem may be?

Any help will be appreciated.

Dim conn As New SqlConnection
        Dim connString As String
        Dim NewTestID As Integer = CType(Session.Item("ID"), Integer)
        Dim NewRegistercode As String
        Try
            connString = "Data Source=(LocalDB)\v11.0;AttachDbFilename=G:\EPQ\Program\Times Tables - Copy\Times Tables\App_Data\TimesTablesDB.mdf;Integrated Security=True"
            conn.ConnectionString = connString
        Catch ex As Exception
            MsgBox("Failed to connect to Database..")
        End Try
        conn.Open()
        Dim da As New SqlDataAdapter("SELECT * FROM Users WHERE StudentID = " & NewTestID & "", conn)
        Dim ds As New DataSet
        da.Fill(ds, "Registercode")
        conn.Close()
        NewRegistercode = ds.Tables("Registercode").Rows(0).Item(3)

        Dim SqlDataSourceAnalysis As New SqlDataSource
        SqlDataSourceAnalysis.ID = "SqlDataSourceAnalysis"
        Me.Page.Controls.Add(SqlDataSourceAnalysis)
        SqlDataSourceAnalysis.ConnectionString = connString
        SqlDataSourceAnalysis.SelectCommand = "SELECT Users.Username, Test.CorrectQ, Test.TotalQ, Test.Percentage, Test.DateofTest FROM Users INNER JOIN Test ON Users.StudentID = Test.StudentID WHERE Users.Student = 1 AND Users.RegisterCode = '" & NewRegistercode & "'"
        datagridAnalyis.DataSource = SqlDataSourceAnalysis
        datagridAnalyis.DataBind()



Is This A Good Question/Topic? 0
  • +

Replies To: Gridview not outputting data

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14091
  • View blog
  • Posts: 56,453
  • Joined: 12-June 08

Re: Gridview not outputting data

Posted 04 February 2017 - 04:50 PM

Try using just the dataset's table.
Was This Post Helpful? 0
  • +
  • -

#3 alanSmirnov   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 26-January 17

Re: Gridview not outputting data

Posted 04 February 2017 - 04:54 PM

View Postmodi123_1, on 04 February 2017 - 04:50 PM, said:

Try using just the dataset's table.


used this code , same problem

conn.Open()
        Dim da1 As New SqlDataAdapter("SELECT Users.Username, Test.CorrectQ, Test.TotalQ, Test.Percentage, Test.DateofTest FROM Users JOIN Test ON Users.StudentID = Test.StudentID WHERE Users.Student = 1 AND Users.RegisterCode) ='" & NewRegistercode & "'", conn)
        Dim dt1 As New DataTable
        da1.Fill(dt1)
        conn.Close()
        datagridAnalyis.DataSource = dt1
        datagridAnalyis.DataBind()

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14091
  • View blog
  • Posts: 56,453
  • Joined: 12-June 08

Re: Gridview not outputting data

Posted 04 February 2017 - 05:09 PM

Are you sure you have data?
Was This Post Helpful? 0
  • +
  • -

#5 alanSmirnov   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 26-January 17

Re: Gridview not outputting data

Posted 04 February 2017 - 05:12 PM

View Postmodi123_1, on 04 February 2017 - 05:09 PM, said:

Are you sure you have data?


These are the tables in the sql server
TEST:

2 9 10 90.00 01/02/2017
NULL NULL NULL NULL NULL

USERS:

1 admin [email protected] Admin False
2 alan [email protected] Cardinal223Newman False
3 smirnovsa1 [email protected] Cardinal223Newman True
NULL NULL NULL NULL NULL
Was This Post Helpful? 0
  • +
  • -

#6 alanSmirnov   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 26-January 17

Re: Gridview not outputting data

Posted 05 February 2017 - 03:41 AM

Anyone help?
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14091
  • View blog
  • Posts: 56,453
  • Joined: 12-June 08

Re: Gridview not outputting data

Posted 05 February 2017 - 11:03 AM

You should be using a try/catch around there to see if you are getting errors.
Visually I see a stray ) in there. Remove that.

Next, put a break point at the top and step through it. See if the data is making it in, or just failing to get into the grid.
Was This Post Helpful? 0
  • +
  • -

#8 alanSmirnov   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 26-January 17

Re: Gridview not outputting data

Posted 05 February 2017 - 11:41 AM

View Postmodi123_1, on 05 February 2017 - 11:03 AM, said:

You should be using a try/catch around there to see if you are getting errors.
Visually I see a stray ) in there. Remove that.

Next, put a break point at the top and step through it. See if the data is making it in, or just failing to get into the grid.


i have found the error in the tables but i still cant get data into the datagridview even though the datatable has 1 valid record
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1