Gridview not showing results of query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dougancil
    Contributor
    • Apr 2010
    • 347

    Gridview not showing results of query

    I have the following code on my page

    [code]
    Imports System.Data.Sql Client
    Imports System.Data
    Partial Class _Default
    Inherits System.Web.UI.P age
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load
    TimeDateLabel.T ext = String.Format(" Today is {0:F}", DateTime.Now)
    schedulenameBox .Focus()
    End Sub
    Protected Sub GetOncall()
    Dim dt As New DataTable
    Dim da As New SqlDataAdapter
    Dim cmd As New SqlCommand
    Dim connectionStrin g As String = "Initial Catalog=mdr;Dat a Source=xxxxx;ui d=xxxxx;passwor d=xxxxx"
    Dim con As New SqlConnection(c onnectionString )
    con.Open()
    cmd.Connection = con
    cmd.CommandType = CommandType.Sto redProcedure
    cmd.CommandText = "sp_getoncallre sults"
    cmd.Parameters. AddWithValue("@ schedname", schedulenameBox .Text)
    cmd.Parameters. AddWithValue("@ sincedate", sincedateBox.Te xt)
    Try
    da.SelectComman d = cmd
    da.Fill(dt)
    GridView1.DataS ource = dt
    GridView1.DataB ind()
    con.Dispose()
    Catch ex As Exception
    Response.Write( "Error:" & ex.Message)
    End Try
    End Sub

    Protected Sub clearButton_Cli ck(ByVal sender As Object, ByVal e As System.EventArg s) Handles clearButton.Cli ck
    schedulenameBox .Text = ""
    sincedateBox.Te xt = ""
    GridView1.DataS ource = Nothing
    GridView1.DataB ind()
    End Sub
    End Class
    [code]

    and I can see that my values are passed to my variables when I debug the code but the results for my datatable show 0 rows. Can someone tell me what I may have done wrong?

    Thank you

    Doug
  • VijaySofist
    New Member
    • Jun 2007
    • 107

    #2
    Hi,

    Check once whether you called the "GetOncall" Procedure. Because in the code you submitted it never seems to be called. Try Calling that Procedure in the Page_Load and also check ISPostBack Condition.

    Regards
    Vijay.R

    Comment

    Working...