473,406 Members | 2,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

SelectCommand.Connection property has not been initialized

347 100+
I have the following code for a web page that I'm working on:

Expand|Select|Wrap|Line Numbers
  1. Imports System.Data.SqlClient
  2. Imports System.Data
  3. Partial Class _Default
  4.     Inherits System.Web.UI.Page
  5.     Protected Sub whosoncallButton_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles whosoncallButton.Click
  6.         Dim dt As New DataTable
  7.         Dim da As New SqlDataAdapter
  8.         Dim cmd As New SqlCommand
  9.         Dim connectionString As String = "Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxx"
  10.         Dim con As New SqlConnection(connectionString)
  11.         con.Open()
  12.         cmd.CommandType = CommandType.StoredProcedure
  13.         cmd.CommandText = "getoncall"
  14.         cmd.Parameters.AddWithValue("@subschedule", TextBox1.Text)
  15.         Try
  16.             da.SelectCommand = cmd
  17.             da.Fill(dt)
  18.             GridView1.DataSource = dt
  19.             GridView1.DataBind()
  20.             con.Dispose()
  21.         Catch ex As Exception
  22.             Response.Write("Error:" & ex.ToString)
  23.         End Try
  24.     End Sub
  25.  
  26.     Protected Sub clearButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles clearButton.Click
  27.         TextBox1.Text = ""
  28.     End Sub
  29. End Class
  30.  
when the buttonclick event fires I receive the following error:

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
  1.  da.Fill(dt)
  2.  
and I can't figure out what this error message means. Can someone please assist me on what this error message is?

Thank you

Doug
Mar 10 '11 #1
0 1799

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: MattB | last post by:
I'm trying to implement an example I found for displaying images stored in a SQL database. The example code looks like this (in page_load): Dim connstr As String = "Integrated...
2
by: CJM | last post by:
I'm not sure where I cam going wrong here... I'm getting the runtime error above, but my code seems reasonable. Am I missing something? Code Snippet: oConn = New SqlConnection...
9
by: Taishi | last post by:
ExecuteReader: Connection property has not been initialized. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more...
3
by: Jason Williard | last post by:
I am trying to create a web form that will be used to create new users. The first step that I am taking is creating a web form that can check the username against a database to see if it already...
4
by: phil | last post by:
Hi, With the code below, i get the error: ExecuteReader: Connection property has not been initialized. Description: An unhandled exception occurred during the execution of the current web...
7
by: Lawrence 007 | last post by:
Hi, I am new to VB.Net and I am trying to create a program that inserts data into a SQL table. Below you will find my code that gives me the following error: Connection Property has not been...
0
by: billy.murray | last post by:
I have a system which comprises 4 servers (1 server per plant area). Each plant area server has 2 databases (Config<nand Runtime<nwhere <nis the plant area number) and 1 web application which uses...
2
by: nada111 | last post by:
SelectCommand.Connection property has not been initialized
0
by: santiago8000 | last post by:
hello,i'm new to vb.net,and i'm trying to do my first program for my training...my program is about the Northwind2 database in sql server,i have a "ShowAll" button,that displays in a form the...
1
by: mamtaid | last post by:
i have the following code.... it gives the error::ExecuteReader: Connection property has not been initialized can anyone please help me sst = new DataSet(); asq = new...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.