I have the following code in my asp page:

Imports System.Data.SqlClient
Imports System.Data
Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim dt As DataTable
        Dim connectionString As String = "Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxx"
        Dim con As New SqlConnection(connectionString)
        Dim cmd As New SqlCommand
        cmd.Connection = con
        con.Open()
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "getoncall"
        cmd.Parameters.AddWithValue("@subschedule", TextBox1.Text)
        cmd.ExecuteNonQuery()
        Using da As New SqlDataAdapter(cmd)
            dt = New DataTable
            da.Fill(dt)
            GridView1.DataSource = dt
            GridView1.EmptyDataText = "No Records Found"
            GridView1.DataBind()
            con.Close()
            con.Dispose()
        End Using
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = ""
    End Sub
End Class

and while the page doesn't throw me any errors, I'm also not seeing any data in my datatable. Can anyone maybe see why?

Thank you

First, you dont need this line cmd.ExecuteNonQuery()
Second, when using fill a dataset thru an adapter you dont need to open and close the connection that is done automatically.

everything looks good just take out the cmd.ExecuteNonQuery()

jbisono,

I've modified the code as you suggested:

Imports System.Data.SqlClient
Imports System.Data
Partial Class _Default
    Inherits System.Web.UI.Page
    Protected Sub whosoncallButton_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles whosoncallButton.Click
        Dim dt As DataTable
        Dim da As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter
        Dim connectionString As String = "Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxx"
        Dim con As New SqlConnection(connectionString)
        Dim cmd As New SqlCommand
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "getoncall"
        cmd.Parameters.AddWithValue("@subschedule", TextBox1.Text)
        Try
            dt = New DataTable
            da.Fill(dt)
            GridView1.DataSource = dt
            GridView1.EmptyDataText = "No Records Found"
            GridView1.DataBind()
            con.Dispose()
        Catch ex As Exception
        End Try
    End Sub

    Protected Sub clearButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles clearButton.Click
        TextBox1.Text = ""
    End Sub
End Class

and I'm still not seeing anything on my page

here is the aspx portion of the page ... as you can see ... there's not much to it:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .style1
        {
            text-align: center;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="style1">
        <br />
        <br />
        <br />
        <br />
        <br />
        Enter Your Schedule Name Below<br />
        <br />
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:Button ID="whosoncallButton" runat="server" Text="Who's On Call" />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="clearButton" runat="server" Text="Clear" />
        <br />
        <br />
        <br />
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
    </div>
    </form>
</body>
</html>

Uhmm to be honest im more with c# but i always say that it is the same thing, in the only other thing that i can tell you is, in your aspx page the button whosoncallbutton you have to add the property onClick="whosoncallButton_click"

also, check again the connection, the name of the stored procedure and the parameters.

if that does not work instead of filling a datatable try to fill a dataset and add the dataset as datasource, just to test.

This article has been dead for over six months. Start a new discussion instead.