473,795 Members | 3,024 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to fix "SelectedComman d property has not been initialized . . " error?

347 Contributor
I have the following code:

Expand|Select|Wrap|Line Numbers
  1. Public Class Payrollfinal
  2.     Private Sub Payrollfinal_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  3.         exportfileButton.Enabled = False
  4.         Dim oCmd As System.Data.SqlClient.SqlCommand
  5.         Dim oDr As System.Data.SqlClient.SqlDataReader
  6.         oCmd = New System.Data.SqlClient.SqlCommand
  7.         Dim _CMD As SqlCommand = New SqlCommand
  8.         Dim adapter As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter
  9.         Dim ds As New DataSet
  10.         Try
  11.             adapter.Fill(ds)
  12.             With oCmd
  13.                 .Connection = New System.Data.SqlClient.SqlConnection("Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxx")
  14.                 .Connection.Open()
  15.                 .CommandType = CommandType.StoredProcedure
  16.                 .Parameters.AddWithValue("@payperiodstartdate", payperiodstartdate)
  17.                 .Parameters.AddWithValue("@payperiodenddate", payperiodenddate)
  18.                 .CommandText = "sp_allsum"
  19.                 oDr = .ExecuteReader()
  20.                 oCmd.Connection.Close()
  21.             End With
  22.         Catch ex As Exception
  23.             MessageBox.Show(ex.Message)
  24.         End Try
  25.  
  26.         Try
  27.         Catch ex As Exception
  28.             MessageBox.Show(ex.Message)
  29.             oCmd.Connection.Close()
  30.         End Try
  31.         exportfileButton.Enabled = True
  32.     End Sub
  33.  
and when I press the button that this event is connected to, I get the error:

The SelectCommand Property has not been initialized before calling 'Fill'

and I'm thinking that because on my other page, where I'm trying to run multiple queries with this code;
Expand|Select|Wrap|Line Numbers
  1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  2.         Main.payrollButton.Enabled = True
  3.         Main.exceptionsButton.Enabled = False
  4.         Dim oCmd As System.Data.SqlClient.SqlCommand
  5.         oCmd = New System.Data.SqlClient.SqlCommand
  6.         Dim adapter As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter
  7.         Dim ds As New DataSet
  8.         Try
  9.             With oCmd
  10.                 .Connection = New System.Data.SqlClient.SqlConnection("Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxx")
  11.                 .Connection.Open()
  12.                 .CommandType = CommandType.StoredProcedure
  13.                 .CommandText = "exec sp_opsum @payperiodstartdate = " + payperiodstartdate + ",@payperiodenddate=" + payperiodenddate + ";" + _
  14. "exec sp_opintcheck @payperiodstartdate = " + payperiodstartdate + ",@payperiodenddate=" + payperiodenddate + ";" + _
  15. "exec sp_opexceptsum @payperiodstartdate = " + payperiodstartdate + ",@payperiodenddate=" + payperiodenddate + ";" + _
  16. "exec sp_empsum @payperiodstartdate = " + payperiodstartdate + ",@payperiodenddate=" + payperiodenddate + ";" + _
  17. "exec sp_empexceptsum @payperiodstartdate = " + payperiodstartdate + ",@payperiodenddate=" + payperiodenddate + ";"
  18.                 oCmd.Connection.Close()
  19.             End With
  20.         Catch ex As Exception
  21.             MessageBox.Show(ex.Message)
  22.         End Try
  23.  
  24.         Try
  25.  
  26.         Catch ex As Exception
  27.             MessageBox.Show(ex.Message)
  28.             oCmd.Connection.Close()
  29.         End Try
  30.         Me.Close()
  31.     End Sub
  32.  
Jan 27 '11 #1
0 1069

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

Similar topics

1
2168
by: Denzil | last post by:
Hi, I am using the DataView.Sort Property (on a DataView column) to sort the View based on some condition. Now the column that I need to sort contains characters and HTML code that should not be considered when sorting is done. (e.g. -> <B>, <FONT ...>, " , ' , etc...). To illustarte: Example 1
3
4845
by: | last post by:
This is a semi-advanced question about ASP VBScript 5.0 classes. If you're knowledegable, please lend a hand! VBScript class instances can have properties that have objects assigned to them. Borrowing R.Quinn's example from ASP101: Public Property Get Authors() if not isobject(m_Authors) then set Library = New cLibrary Call Library.GetAuthorsByBookID(Me.ID)
5
2181
by: Mike | last post by:
My first simple attempt at using a property. and I get an exception "An unhandled exception of type 'System.StackOverflowException' occurred in BalanceOmatic.exe" on line xxx. I have included the property code and the button event used to set and call the property value. Any help greatly appreciated. What am I missing?
4
1607
by: Mervin Williams | last post by:
I have several tables involved in my application, but the two in question here are the company and address tables. The company table has business_address_id and mailing_address_id columns, which are both foreign keys to the address table. So, the stored procedure to which my SelectCommand points to reads as: ALTER PROCEDURE dbo.CompanyInfoByCompanyID ( @companyid int
2
2216
by: etropic | last post by:
I am trying to bind two tables to two different list boxes Ther tables are working as I use them on another page wth no problems The code is as follows... private void Page_Load(object sender, System.EventArgs e oleDbDataAdapter2.Fill( dataSet1) oleDbDataAdapter4.Fill( dataSet1)
6
10994
by: M | last post by:
Hi, Does SqlDataAdapter always close the connection (assuming connection was closed before calling Fill()), even if an exception occurs while calling Fill()? Example: try { myDataAdapter.Fill(myDataTable);
4
6969
by: CJ Taylor | last post by:
Hey, how do I use the anchor property? I have it set to Top, Left, but when I expand the form, it doesn't grow with it... What am I missing? Thanks, CJ
7
5226
by: Zytan | last post by:
I just wanted a little practice with the WebBrowser control, so I did the VB guided tour example here in C#: http://msdn2.microsoft.com/en-us/library/a08t4ke7(VS.80).aspx The tutorial asks to put a Panel with a Button and TextBox in it, and a WebBrowser below it. Then, it sets the Panel's Dock property to be Top. It sets the WebBroswer's Dock property to be Fill. But, the WebBrowser then fills the entire form! Even though the Panel's...
1
1075
by: Rachana | last post by:
Hi, I am having vb2003-net 1.1 Code was working fine yesterday, today getting error ----------------------------------------------------------- error: An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll Additional information: System error. -----------------------------------------------------------
8
1644
by: Ethan Kennerly | last post by:
Hello, There are a lot of Python mailing lists. I hope this is an appropriate one for a question on properties. I am relatively inexperienced user of Python. I came to it to prototype concepts for videogames. Having programmed in C, scripted in Unix shells, and scripted in a number of proprietary game scripting languages, I'm impressed at how well Python meets my needs. In almost all respects, it does what I've been wishing a...
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10439
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.