473,320 Members | 2,041 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,320 software developers and data experts.

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

347 100+
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 1050

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

Similar topics

1
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...
3
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....
5
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...
4
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...
2
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...
6
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 {...
4
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
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...
1
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...
8
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.