Link to home
Start Free TrialLog in
Avatar of David Megnin
David MegninFlag for United States of America

asked on

How to add Parameters to a SQL INSERT statement

I have a Stored Procedure I'm trying to use to add records from an ASP.Net 2.0/VB webform into a SQL Server 2000 database.

This seems to be working (no errors so far):
        cmdTest.Parameters.Add(New SqlParameter("@txtContactContract", Data.SqlDbType.VarChar, 10))
        cmdTest.Parameters("@txtContactContract").Value = txtContactContractTitle.Text

but I want to shorten it to something like:
cmdTest.Parameters.Add(New SqlParameter("@txtContactContract", SqlDbType.VarChar).Value = txtContactContract.Text)

but I get this error:
The SqlParameterCollection only accepts non-null SqlParameter type objects, not Boolean objects.

What did I do wrong?

ALTER Procedure sp_SYEP_Employers_NewRecord
		@txtEmployerName varchar(50), 
		@ddlOrganizationType varchar(50), 
		@txtFedID varchar(50), 
		@txtContactContract varchar(50), 
		@txtContactContractTitle varchar(50), 
		@txtCompanyStreet varchar(50), 
		@txtCompanyCity varchar(50), 
		@txtCompanyState varchar(50), 
		@txtCompanyZip varchar(50), 
		@txtCompanyContractContactTelephone varchar(50), 
		@txtCompanyContractContactFAX varchar(50), 
		@txtCompanyContractContactCell varchar(50), 
		@txtCompanyContractContactEmail varchar(50), 
		@txtContactProgram varchar(50), 
		@txtContactProgramTitle varchar(50), 
		@txtContactProgramAddress varchar(50), 
		@txtContactProgramCity varchar(50),	
		@txtContactProgramState varchar(50), 
		@txtContactProgramZip varchar(50), 
		@txtContactProgramPhone varchar(50), 
		@txtContactProgramFAX varchar(50),
		@txtContactProgramCell varchar(50), 
		@txtContactProgramEmail varchar(50), 
		@txtWorksitesRequestedNumber varchar(50), 
		@ddlOrgHasContract varchar(50), 
		@ddlConfirmUnderstand varchar(50)
 
AS
 
SET NOCOUNT ON
 
INSERT Employers(
	txtEmployerName, ddlOrganizationType, txtFedID, txtContactContract, txtContactContractTitle, 
	txtCompanyStreet, txtCompanyCity, txtCompanyState, txtCompanyZip, txtCompanyContractContactTelephone, 
	txtCompanyContractContactFAX, txtCompanyContractContactCell, txtCompanyContractContactEmail, 
	txtContactProgram, txtContactProgramTitle, txtContactProgramAddress, txtContactProgramCity, 
	txtContactProgramState, txtContactProgramZip, txtContactProgramPhone, txtContactProgramFAX, 
	txtContactProgramCell, txtContactProgramEmail, txtWorksitesRequestedNumber, ddlOrgHasContract, 
	ddlConfirmUnderstand, ApplicationDateEmployer
	) 
VALUES (@txtEmployerName, @ddlOrganizationType, @txtFedID, @txtContactContract, @txtContactContractTitle, 
	@txtCompanyStreet, @txtCompanyCity, @txtCompanyState, @txtCompanyZip, @txtCompanyContractContactTelephone, 
	@txtCompanyContractContactFAX, @txtCompanyContractContactCell, @txtCompanyContractContactEmail, 
	@txtContactProgram, @txtContactProgramTitle, @txtContactProgramAddress, @txtContactProgramCity,	
	@txtContactProgramState, @txtContactProgramZip, @txtContactProgramPhone, @txtContactProgramFAX,
	@txtContactProgramCell, @txtContactProgramEmail, @txtWorksitesRequestedNumber, @ddlOrgHasContract, @ddlConfirmUnderstand,getdate()
	)
 
Select	SCOPE_IDENTITY() priKeyEmployers
 
RETURN

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of MikeToole
MikeToole
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of David Megnin

ASKER

Thank you very much MikeToole and imitchie!  
Conceptinfotech, thank you for your comment also, but since I am just learning, the direct answers were much more helpful.
Thank you.  I see what I did wrong.  The devil is in the details, isn't it?