Expand|Select|Wrap|Line Numbers
- 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 New DataTable
- Dim da As New SqlDataAdapter
- Dim cmd As New SqlCommand
- Dim connectionString As String = "Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxx"
- Dim con As New SqlConnection(connectionString)
- con.Open()
- cmd.CommandType = CommandType.StoredProcedure
- cmd.CommandText = "getoncall"
- cmd.Parameters.AddWithValue("@subschedule", TextBox1.Text)
- Try
- da.SelectCommand = cmd
- da.Fill(dt)
- GridView1.DataSource = dt
- GridView1.DataBind()
- con.Dispose()
- Catch ex As Exception
- Response.Write("Error:" & ex.ToString)
- 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
Error:System.InvalidOperationException: Fill: SelectCommand.Connection property has not been initialized. at System.Data.Common.DbDataAdapter.GetConnection3(Db DataAdapter adapter, IDbCommand command, String method) at System.Data.Common.DbDataAdapter.FillInternal(Data Set dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) at _Default.whosoncallButton_click(Object sender, EventArgs e) in L:\wwwroot\WebSite1\Default.aspx.vb:line 17
this is line 17
Expand|Select|Wrap|Line Numbers
- da.Fill(dt)
Thank you
Doug