Wednesday, March 28, 2012

Invalid Syntax in my sproc?!?!

Hi I have a gridview that is being populated from a method that gets it's data from a table view.

SELECT dbo.cis_AlumniContact.Street, dbo.cis_AlumniContact.City, dbo.cis_AlumniContact.State, dbo.cis_AlumniContact.Telephone,
dbo.cis_AlumniContact.Occupation, dbo.cis_AlumniContact.Description, dbo.cis_AlumniContact.Zip, dbo.cis_AlumniContact.FirstName,
dbo.cis_AlumniContact.LastName, dbo.cis_AlumniContact.YearGraduate, dbo.cis_AlumniContact.Email, dbo.cis_AlumniContact.Contact,
dbo.aspnet_Users.UserName, dbo.cis_StudentId.UaaStudentId
FROM dbo.aspnet_Users INNER JOIN
dbo.cis_AlumniContact ON dbo.aspnet_Users.UserId = dbo.cis_AlumniContact.UserId INNER JOIN
dbo.cis_StudentId ON dbo.aspnet_Users.UserId = dbo.cis_StudentId.UserId

No big deal, works great. Now when I click update I call this method

<DataObjectMethod(DataObjectMethodType.Update)>

PublicSub UpdateAlumni(ByVal StreetAsString,ByVal CityAsString,ByVal StateAsString,ByVal TelephoneAsString,ByVal OccupationAsString,ByVal DescriptionAsString,ByVal ZipAsString,ByVal FirstNameAsString,ByVal LastNameAsString,ByVal YearGraduateAsString,ByVal EmailAsString,ByVal ContactAsBoolean,ByVal original_UserNameAsString,ByVal UaaStudentIdAsString)TryDim connxAsNew SqlConnection(getConnectionString)

connx.Open()

Dim sqlCmdAsNew SqlCommand("cis_UpdateAlumniContact", connx)

sqlCmd.Parameters.Add(

New SqlParameter("@.UserName", SqlDbType.NVarChar))

sqlCmd.Parameters(

"@.UserName").Value = original_UserName

sqlCmd.Parameters.Add(

New SqlParameter("@.FirstName", SqlDbType.NVarChar))

sqlCmd.Parameters(

"@.FirstName").Value = FirstName

sqlCmd.Parameters.Add(

New SqlParameter("@.LastName", SqlDbType.NVarChar))

sqlCmd.Parameters(

"@.LastName").Value = LastName

sqlCmd.Parameters.Add(

New SqlParameter("@.Email", SqlDbType.NVarChar))

sqlCmd.Parameters(

"@.Email").Value = Email

sqlCmd.Parameters.Add(

New SqlParameter("@.Street", SqlDbType.NVarChar))

sqlCmd.Parameters(

"@.Street").Value = Street

sqlCmd.Parameters.Add(

New SqlParameter("@.City", SqlDbType.NVarChar))

sqlCmd.Parameters(

"@.City").Value = City

sqlCmd.Parameters.Add(

New SqlParameter("@.State", SqlDbType.NVarChar))

sqlCmd.Parameters(

"@.State").Value = State

sqlCmd.Parameters.Add(

New SqlParameter("@.Occupation", SqlDbType.NVarChar))

sqlCmd.Parameters(

"@.Occupation").Value = Occupation

sqlCmd.Parameters.Add(

New SqlParameter("@.Description", SqlDbType.NVarChar))

sqlCmd.Parameters(

"@.Description").Value = Description

sqlCmd.Parameters.Add(

New SqlParameter("@.Telephone", SqlDbType.NChar))

sqlCmd.Parameters(

"@.Telephone").Value = Telephone

sqlCmd.Parameters.Add(

New SqlParameter("@.Zip", SqlDbType.NChar))

sqlCmd.Parameters(

"@.Zip").Value = Zip

sqlCmd.Parameters.Add(

New SqlParameter("@.Contact", SqlDbType.Bit))

sqlCmd.Parameters(

"@.Contact").Value = Contact

sqlCmd.Parameters.Add(

New SqlParameter("@.YearGraduate", SqlDbType.NVarChar))

sqlCmd.Parameters(

"@.YearGraduate").Value = YearGraduateDim cmdAs SqlDataReader = sqlCmd.ExecuteReaderCatch exAs ExceptionDim erAsNew cis_ODS_Error

er.InsertError(

"cis_ODS_Alumni - UpdateAlumni: " + ex.Message.ToString)EndTryEndSub

The sproc it calls is:

ALTER PROCEDURE

dbo.cis_UpdateAlumniContact

@.UserName

as nvarchar(50),

@.Street

as nvarchar(50),

@.City

as nvarchar(50),

@.State

as nvarchar(2),

@.Telephone

as nvarchar(50),

@.Occupation

as nvarchar(50),

@.Description

as nvarchar(50),

@.Zip

as nvarchar(50),

@.FirstName

as nvarchar(50),

@.LastName

as nvarchar(50),

@.YearGraduate

as nvarchar(4),

@.Email

as nvarchar(50),

@.Contact

as bit

AS

UPDATEcis_AlumniContact

SETStreet = @.Street, City = @.City, State = @.State, Telephone = @.Telephone, Occupation = @.Occupation, Description = @.Description, Zip = @.Zip, FirstName = @.FirstName, LastName = @.LastName, YearGraduate = @.YearGraduate, Email = @.Email, Contact = @.Contact

FROMaspnet_UsersINNER JOINcis_AlumniContact

ONcis_AlumniContact.UserId = aspnet_Users.UserId

WHERE@.UserName = aspnet_Users.UserName

RETURN

I get this vague error

cis_ODS_Alumni - UpdateAlumni: Incorrect syntax near 'cis_UpdateAlumniContact'

If I execute the SQL from the editor it works fine. The only thing different about this sproc and my other update sprocs is the inner join. Any idea? Thanks

I see two possible problems.

You need to set the command type to:StoredProcedure

You are calling ExecuteReader, I think you need to call ExecuteNonQuery.

|||Holy cow man. Thanks so much. I copied and pasted from another method and didn't include that line. Thanks again.

No comments:

Post a Comment