Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 9th, 2010, 12:49 PM
Authorized User
 
Join Date: Jun 2008
Posts: 75
Thanks: 15
Thanked 0 Times in 0 Posts
Default SQLDataReader help

Thanks for any help or suggestions. I am using the SQLDataReader to execute a Stored Procedure that accepts two parameters (BuildingTID and Department) to return the appropritae Value in my case The Director of the Department. My problem is I get the following error when I run the code that I added below for review. Let me also add that the user is selecting the values that I am using for the stored procedure from 2 DropDownLists.

Unable to cast object of type 'System.Boolean' to type 'System.Data.SqlClient.SqlParameter'.





con =
New SqlConnection(ConfigurationManager.ConnectionStrin gs("Connect").ConnectionString)
Dim getDirectorsCMD As SqlCommand = New SqlCommand("dbo.spGetDirector", con)
getDirectorsCMD.CommandType = CommandType.StoredProcedure

Dim myParm As SqlParameter = getDirectorsCMD.Parameters.Add("@BuildingTID", SqlDbType.Int, 15).Value = (ddlDepartment.SelectedValue)
Dim myParm1 As SqlParameter = getDirectorsCMD.Parameters.Add("@Department", SqlDbType.VarChar, 50).Value = (ddlDepartment.SelectedItem.Text)


con.Open()
Dim myReader As SqlDataReader = getDirectorsCMD.ExecuteReader()

With txtDirector
.Enabled =
True
.Text = myReader("Contact Name")
EndWith
con.Close()
con.Dispose()
 
Old February 9th, 2010, 12:52 PM
Authorized User
 
Join Date: Jun 2008
Posts: 75
Thanks: 15
Thanked 0 Times in 0 Posts
Default

Sorry I forgot to mention where I am getting the error. I am getting it when I try to assign the value that is in the Department DropDown list to the first parameter.

Dim myParm As SqlParameter = getDirectorsCMD.Parameters.Add("@BuildingTID", SqlDbType.Int, 15).Value = (ddlDepartment.SelectedValue)
 
Old February 9th, 2010, 12:54 PM
Authorized User
 
Join Date: Jun 2008
Posts: 75
Thanks: 15
Thanked 0 Times in 0 Posts
Default

Also obviously there are more issues with my code than just the error because the datareader records property is false meaning I am not returning a row





Similar Threads
Thread Thread Starter Forum Replies Last Post
sqlDatareader dovk179 ASP.NET 2.0 Professional 1 January 26th, 2010 03:06 AM
Inheriting SqlDataReader and new KeyWord software_developer_kk C# 2 June 28th, 2007 08:17 AM
SqlDataReader testsubject ADO.NET 9 March 7th, 2006 06:08 PM
looping through columns in sqldatareader rlull ASP.NET 1.0 and 1.1 Basics 1 November 5th, 2005 02:32 AM
Urgent getting Error while using SqlDataReader hums ADO.NET 2 September 29th, 2004 10:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.