Error when attempting to insert record using stored procedure

I am trying to save user data to a sql table but keep getting the following error;

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

I am using VWD Express Edition with .NET 2.0 and a SQL 2000 database. The code that generates the error is as follows;

Public

Function chkUser(ByVal strUser As String) As String
d
im MyConnection As SqlConnection
Dim MyCommand As SqlCommand
Dim ReturnString As String
Dim params As SqlParameter
Dim SelectCmd As String = "wm_CheckUser"
MyConnection = New SqlConnection(myConnectionString)
MyCommand =
New SqlCommand(SelectCmd, MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure

Try
params = MyCommand.Parameters.Add("@parUser", SqlDbType.VarChar, 100).Value = strUser
MyCommand.Connection.Open()
MyCommand.ExecuteNonQuery()
ReturnString =
"Record Exists!"
Catch Exp As SqlException
ReturnString = ReturnError(Exp.Number,
"Users", Exp.Message)
End Try
MyCommand.Connection.Close()
Return ReturnString

End Function

Basically, I'm traying to check to see if a user id already exists in the database before saving the data the user entered. If the email address entered by the user is already in the database I want a message to be shown to the user. If the email address does not exist then the data entered by the user is saved and the form goes to step two (2) of the user registration process.

Any help with this would be greately appreciated. I can't seem to see what is wrong here. Please someone help.

Thanks,

Jaime

0
jmawebco
6/22/2006 12:25:40 AM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

7 Replies
642 Views

Similar Articles

[PageSpeed] 33
Get it on Google Play
Get it on Apple App Store

try this 

Try
MyCommand.Parameters.Add("@parUser", SqlDbType.VarChar, 100)
MyCommand.Parameters[0].Value = strUser
......
...

 If this still not work, post your stored procedure here, we can look at  more.

0
DavidDu
6/22/2006 12:42:03 AM

I tried you suggestion and now I get the following;

The ConnectionString property has not been initialized.

Line 66:                 MyCommand.Parameters("@parUser").Value = strUser
Line 67:
Line 68:                 MyCommand.Connection.Open()
Line 69:                 MyCommand.ExecuteNonQuery()
Line 70:                 ReturnString = "Record Exists!"

0
jmawebco
6/22/2006 1:43:40 AM
 in your code:
MyConnection = New SqlConnection(myConnectionString)
MyCommand = New SqlCommand(SelectCmd, MyConnection)
where did you define the variable "myConnectionString", you have to verify you have a valiade connection string before this line
0
DavidDu
6/22/2006 4:21:17 AM

Here is the code found in my class file which I use to hold all data relevant code. The connection string is in my web.config file which is why the line under the New Public Sub sets the value of myConnectionString equal to System.Configuration.ConfigurationManager.AppSettings("SiteConnectionString").

Any ideas would be welcomed since I am pretty much stuck here.

Thanks. 

Public Class DataClass

Public myConnectionString As String
Public Sub New()
MyBase.New()
'Used In Production Environment (Uncomment line below when in Production)
'myConnectionString = ConfigurationSettings.AppSettings("connectionstring")
'Used In Development Environment (Comment line below when in Production)
myConnectionString = System.Configuration.ConfigurationManager.AppSettings("SiteConnectionString")
End Sub

Public

Function chkUser(ByVal strUser As String) As String
Dim MyConnection As SqlConnection
Dim MyCommand As SqlCommand
Dim ReturnString As String
'Dim params As SqlParameter
Dim SelectCmd As String = "wm_CheckUser"
MyConnection = New SqlConnection(myConnectionString)
MyCommand =
New SqlCommand(SelectCmd, MyConnection)
MyCommand.CommandType = CommandType.StoredProcedure
MyCommand.Connection.Open()
Try
MyCommand.Parameters.Add("@parUser", SqlDbType.VarChar, 100)
MyCommand.Parameters(
"@parUser").Value = strUser
MyCommand.ExecuteNonQuery()
ReturnString =
"Record Exists!"
Catch Exp As SqlException
ReturnString = ReturnError(Exp.Number,
"Users", Exp.Message)
End Try
MyCommand.Connection.Close()
Return ReturnString
End Function

End

Class
0
jmawebco
6/23/2006 12:37:53 AM

Put a break point at this line of code, run under debug mode,

MyConnection = New SqlConnection(myConnectionString)

When code stopped, examine the myConnectionString, verify it contain the right coonection string

 

Hope this help

0
DavidDu
6/23/2006 8:49:32 PM

Thank you very much for all your help. I found the problem and it was that I was using a obsolete call to application setting in the web.config file which is no longer used in the 2.0 framework. My oversight when I converted the project from 1.1 to 2.0.

Thanks again for the help.

0
jmawebco
6/24/2006 4:15:17 AM
I thought you were using 1.1, when I saw you use appsetting. It is great you solve the problem
0
DavidDu
6/24/2006 4:36:32 AM
Reply:

Similar Artilces:

View Inserted Record Using Object Datasource, Details View and Stored Procedure
I am trying to display the record just inserted into a database using an object datasource, a stored procedure and a details view Below is the stored procedureALTER PROCEDURE [dbo].[Employees_Insert]( @LastName varchar(50), @FirstName varchar(30) = null, @JobTitle varchar(50))AS SET NOCOUNT OFF;INSERT INTO [dbo].[Employees] ([LastName], [FirstName], [JobTitle])VALUES (@LastName, @FirstName, @JobTitle);  SELECT  LastName, FirstName, JobTitleFROM Employees WHERE (EmployeeID = SCOPE_IDENTITY()) ________________________________________________________________...

Insert multiple records using one stored procedure call. SQL SERVER 7
Hi I have asp.net page with approx 28 dropdowns. I need to insert these records using one stored procedure call. How can I do this while not sacrificing performance?   Thanks, GaryGary Gary, I'm not clear on exactly what you're asking. 28 dropdowns equates to 28 parameters in your stored procedure if you're just inserting a record. Can you provide more details? BruceBrucePlease remember to click "Mark as Answer" on the posts that helped solve your issue. Ok Chuck, never mind about the dropdowns. All Im ask is how to insert multiple records into a database u...

Use Stored Procedure or insert template to insert a new record?
Hi there, I am using stored procedure for all my database website before I use .net 2. When I come to .net 2, I found almost all the videoes are using SP for select functions, and using insert template to add new ones. What's the differenence and which way is better? Thanks!  >which way is better?Whenever you can, use stored procedures - preferably your own, not some of the autogenerated horrors! If you want some help in generating them - see my post in  http://forums.asp.net/p/1091006/1635955.aspx#1635955 plus the helper bits in http://forums.asp.net/p/1089533/1631113.a...

How to transfer a GUID created using vb.net into a SQL database using a stored procedure
I am able to create a guid using: Public Function GetGUID() As String ' Returns a new GUID Return System.Guid.NewGuid.ToString End Function however when I try to add this to a parameter using the following: Me.cmdSpAddOptions.Parameters("@QuoteDetailID").Value = GetGUID() I get an error, I have also tried this: Dim uidQuoteDetail As String = GetGUID() Dim myuid = New System.Guid(uidQuoteDetail) Me.cmdSpAddOptions.Parameters("@QuoteDetailID").Value = myuid but get the error "Object must implement IConvertible" A...

Using stored procedures to insert recorders
Hi I am not familiar with stored procedures, but I tried to use it with this code and it worked fine   ALTER PROCEDURE dbo.p_insert_shortleave      @Leave_Date datetime,      @Start_time datetime,      @End_time datetime,      @Reason varchar(150),      @Submission_date datetime,      @L_D_id_Priority varchar(20)AS      INSERT INTO HR_Leave_request (Leave_Date, Start_time, End_time, Reason)   ...

sql count using stored procedure withing stored procedure
I have a stored procedure that among other things needs to get a total of hours worked. These hours are totaled by another stored procedure already. I would like to call the totaling stored procedure once for each user which required a loop sort of thing for each user name in a temporary table (already done) total = result from execute totaling stored procedure Can you help with this Thanks It would be easier if you can change the stored procedure into a function. Once you do that, the total can be calculated easily with something like thisSelect Sum(dbo.CalculateHours(User...

Using a stored Procedure to insert a new record
ok I have a stored procedure...... I pass in the variables that are requried....What is the best way to add a record using my stored procedure in VB.net code in a button click event...... How might i do this with a data reader,,data adapter.....OR What.......................Do I need to declare all my varaibles I am adding to this new record in the line after POSCODE or can vb.net do this without a parameter statemetn CREATE procedure dbo.Appt_AddAppt ( @ClinicID int, @AccountNum nvarchar(10), @DOS nvarchar(12), @POSCODE nvarchar(5) ) as Insert ...

how to insert sql stored procedure into vb.net code??
I am trying to create a paged web site from my database file. for that i found an appropriate sql code. the only thing i don't know is how to declare this sql inside the vb. is it supposed to be in the same .aspx file or in another one?? pls help if you know. thank you so much. here's the sql stored procedure: ------------------------------------------------------------ CREATE PROCEDURE sp_PagedItems ( @Page int, @RecsPerPage int ) AS -- We don't want to return the # of rows inserted -- into our temporary table, so turn NOCOUNT ON SET NOCOUNT ON --Cr...

Problem with inserting a Record using textbox and stored procedure
Below is the code for a form with several textboxes that I would like to use the values from to insert a record using a stored procedure. I am not having any sucess. After entering all the values and clicking the submit button no record gets entered. Any help would be greatly appreciated. Thanks in advance Gary <%@ Page Language="VB" Debug="true" %> <%@ import Namespace="System.Data" %> <%@ import Namespace="System.Data.SqlClient" %> <script runat="server"> Sub Register_Click(ByVal sender A...

Inserting a new record from DetailsView using a stored procedure
I am using an <asp:DetailsView ...> on my <asp:Content ...> page.I have the AutoGenerateInsertButton="True".The DataSourceID for the DetailsView is a SQLDataSource.My Insert command uses a stored procedure that takes the fields a input parameters:   InsertCommand="AddMovie" InsertCommandType="StoredProcedure"I am using a stored procedure to do add a record to my table.My question is: After I click on the "New" button and add data to the DetailsView, how do the values entered get to my stored procedure? What am I missing here? ChuckChuck Ops, my stored procedure ...

Error Sorting a GridView with a SQL Stored Procedure DataSource
I have a page with a gridview that gets data from a sql stored procedure.  The gridview renders the data correctly on page load.  When a column header is clicked, the sorting event fires, gets the sort expression and sort order, passes that to the populategridview() sub, and the stored procedure re-runs - sorting in the requested order.  However when the data binds to the gridview after sorting, the sorting event is fired AGAIN, caused the sort order to be wrong.  See sample code:Private Sub PopulateViewTestsGridView(Optional ByVal SortExpression As String = "Su...

Inserting Information into an SQL Database using Stored Procedures
Hello, I'm building an ecommerce website which requires customers to create an account before they go ahead with a purchase. I have a createaccount.aspx page in Visual Web Developer 2005 with text boxes where users can enter their details (email, password, name and address).  I'm trying to insert the information which users type into the text boxes into an SQL database table called Customers. I've dragged and dropped an SQL data source onto my page and have set it to operate on my AddCustomer stored procedure. I've confirgured my data source such that the parameter for...

Using ADO.NET Execute Second Stored Procedure Depending of Output of First Stored Procedure
When a user logs onto the app, I capture their UserId, today's date and thier WINNT using ADO.NET calling a stored procedue-no problem. Now, once the above mention fields have been populated, when the same user logs on again and this time click their daily attendance time, I need to execute and update stored procedure-no problem. Each time the user logs onto the attendance page, they need to be able to view the previuos time stamps, on page load.- no problem The problem is that I cannot get all three to work in concert, although they will work independently, somewhat. Sotred proc...

how to insert the range of ip address in SQL using stored procedures
hi     i need to insert the list of ipaddress using stored procedures. the user will give the from and to range of IP ADDRESS.i've to insert all  the possible ip address between those values. how to do this.. With Thanks.,R.Chezhian.,=============================================Please Mark the helpful post(s) as Answered LEts say the range is from 172.25.50.1 to 172.25.50.30 you can write a WHILE loop to loop through and insert records. There are other ways too but at this time of the night this is the best I can think of without putting any pressure on m...

Web resources about - Error when attempting to insert record using stored procedure - asp.net.sql-datasource

Facebook Seeks Detailed Information From Users Attempting To Block Or Report Other Users
Facebook continued down the path of seeking more information when users report potentially troublesome situations, following up its dialog box ...

Texas Tribune - "I was attempting to block a bill that... - Facebook
"I was attempting to block a bill that would have harmed thousands of women across the state of Texas,” Davis said of her filibuster. “Never ...

Video of Sen. Wendy Davis Attempting to put on Back-Brace During Filibuster - YouTube
If state Sen. Wendy Davis, D-Fort Worth, is charged with one more violation of the filibuster rules, her attempt to talk Senate Bill 5 to death ...

Two arrested attempting to smuggle heroin into the UAE
Two of the 'most active and dangerous' drug smugglers in the UAE were arrested in April in possession of 55 kilograms of heroin by a team of ...

Mother of woman attempting to flee ISIL says she is now at 'great risk'
The family of notorious Islamic State fighter Khaled Sharrouf is seeking to return to Sydney, according to a report.

Attempting to procure a murder charge against AC/DC drummer Phil Rudd withdrawn
AC/DC drummer Phil Rudd's charge of attempting to procure a murder has been withdrawn.

Eight teenage girls arrested after attempting to rob woman in Shellharbour
Eight teenage girls have been arrested after a 19-year-old woman was threatened with a knife at a bus stop in the NSW Illawarra region.

Andrew Davidson arrested after attempting to have sex with drinks trolley
... was ever a reason to quit alcohol, it's this. A 25-year-old Scottish man has been arrested after making a complete fool of himself while attempting ...

Abbott, Attempting To Order Coffee, Declares The Boats Have Stopped.
Prime Minister Tony Abbott has been at the forefront of a ruckus this morning during an incident in which Mr. Abbott was attempting to order ...

Islamic State recruit lived in Sydney before attempting to travel to Syria
Asher Abid Khan was restless and living in Sydney when he began researching ways to travel to Syria or Iraq to join terror group Islamic State, ...

Resources last updated: 12/24/2015 7:39:18 PM