PC Review


Reply
Thread Tools Rate Thread

SQL Exception near keyword 'Procedure'

 
 
darjonase@gmail.com
Guest
Posts: n/a
 
      5th Jul 2006
I am trying to call a Stored Prodecure in my code, and I keep getting
the same error...

system.data.sqlclient.sqlexception: incorrect syntax near the keyword
'Procedure'


I have added my stored procedure as a .sql file and have verified that
it is written correctly in SQL Sever 2005. Below is that stored
procedure...

CREATE PROCEDURE spInsertModels
@ModelName nvarchar(50),
@Photo image,
@PhotoPath nvarchar(255),
@Active bit
AS
INSERT INTO "dbo"."Models" (ModelName, Photo, PhotoPath, Active)
VALUES (@ModelName, @Photo, @PhotoPath, @Active)


The next couple of methods are written in VB.NET 2005 and are shown
below...

'This is the first method called
Private Sub UpdateOrInsertModelsInDB(ByVal changedData As DataTable)
Try
Dim oRow As DataRow
Dim smallIntActive As Int16

For Each oRow In changedData.Rows
smallIntActive = oRow("Active")
If smallIntActive = vbYes Then
smallIntActive = -1
End If


Dim cmdCommand As New SqlCommand
If oRow.RowState = DataRowState.Added Then
'THIS IS WHAT IS CALLED....
AddModelInsertUpdateParameters(cmdCommand, oRow,
smallIntActive, False)
ExecuteInsertSPWithParams(cmdCommand)
Else
AddModelInsertUpdateParameters(cmdCommand, oRow,
smallIntActive, True)
ExecuteUpdateSPWithParams(cmdCommand)
End If
Next
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub


Private Sub AddModelInsertUpdateParameters(ByRef cmdCommand As
SqlCommand, ByVal orow As DataRow, ByVal smallIntActive As Int16, ByVal
update As Boolean)
Try
Dim sqlParam As New SqlParameter

If update Then
sqlParam = cmdCommand.Parameters.Add("@ModelID",
SqlDbType.Int)
sqlParam.Value = orow("ModelID")
End If

sqlParam = cmdCommand.Parameters.Add("@ModelName",
SqlDbType.NVarChar, 50)
sqlParam.Value = orow("ModelName")

sqlParam = cmdCommand.Parameters.Add("@Photo",
SqlDbType.Image)
sqlParam.Value = orow("Photo")

sqlParam = cmdCommand.Parameters.Add("@PhotoPath",
SqlDbType.NVarChar, 255)
sqlParam.Value = orow("PhotoPath")

sqlParam = cmdCommand.Parameters.Add("@Active",
SqlDbType.Bit)
sqlParam.Value = smallIntActive
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub


Private Sub ExecuteInsertSPWithParams(ByVal cmdCommand As
SqlCommand)
Try
Using conn As New SqlConnection(dbClass.connectionString)
conn.Open()

cmdCommand.Connection = conn
cmdCommand.CommandText =
my.Resources.DatabaseCreationScripts.spInsertModels
cmdCommand.ExecuteNonQuery()

conn.Close()
End Using
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub


Any Ideas on why I am getting this error?

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?G=F6ran_Andersson?=
Guest
Posts: n/a
 
      5th Jul 2006
Have you added the stored procedure to the database?

What does my.Resources.DatabaseCreationScripts.spInsertModels contain?


(E-Mail Removed) wrote:
> I am trying to call a Stored Prodecure in my code, and I keep getting
> the same error...
>
> system.data.sqlclient.sqlexception: incorrect syntax near the keyword
> 'Procedure'
>
>
> I have added my stored procedure as a .sql file and have verified that
> it is written correctly in SQL Sever 2005. Below is that stored
> procedure...
>
> CREATE PROCEDURE spInsertModels
> @ModelName nvarchar(50),
> @Photo image,
> @PhotoPath nvarchar(255),
> @Active bit
> AS
> INSERT INTO "dbo"."Models" (ModelName, Photo, PhotoPath, Active)
> VALUES (@ModelName, @Photo, @PhotoPath, @Active)
>
>
> The next couple of methods are written in VB.NET 2005 and are shown
> below...
>
> 'This is the first method called
> Private Sub UpdateOrInsertModelsInDB(ByVal changedData As DataTable)
> Try
> Dim oRow As DataRow
> Dim smallIntActive As Int16
>
> For Each oRow In changedData.Rows
> smallIntActive = oRow("Active")
> If smallIntActive = vbYes Then
> smallIntActive = -1
> End If
>
>
> Dim cmdCommand As New SqlCommand
> If oRow.RowState = DataRowState.Added Then
> 'THIS IS WHAT IS CALLED....
> AddModelInsertUpdateParameters(cmdCommand, oRow,
> smallIntActive, False)
> ExecuteInsertSPWithParams(cmdCommand)
> Else
> AddModelInsertUpdateParameters(cmdCommand, oRow,
> smallIntActive, True)
> ExecuteUpdateSPWithParams(cmdCommand)
> End If
> Next
> Catch ex As Exception
> MessageBox.Show(ex.ToString)
> End Try
> End Sub
>
>
> Private Sub AddModelInsertUpdateParameters(ByRef cmdCommand As
> SqlCommand, ByVal orow As DataRow, ByVal smallIntActive As Int16, ByVal
> update As Boolean)
> Try
> Dim sqlParam As New SqlParameter
>
> If update Then
> sqlParam = cmdCommand.Parameters.Add("@ModelID",
> SqlDbType.Int)
> sqlParam.Value = orow("ModelID")
> End If
>
> sqlParam = cmdCommand.Parameters.Add("@ModelName",
> SqlDbType.NVarChar, 50)
> sqlParam.Value = orow("ModelName")
>
> sqlParam = cmdCommand.Parameters.Add("@Photo",
> SqlDbType.Image)
> sqlParam.Value = orow("Photo")
>
> sqlParam = cmdCommand.Parameters.Add("@PhotoPath",
> SqlDbType.NVarChar, 255)
> sqlParam.Value = orow("PhotoPath")
>
> sqlParam = cmdCommand.Parameters.Add("@Active",
> SqlDbType.Bit)
> sqlParam.Value = smallIntActive
> Catch ex As Exception
> MessageBox.Show(ex.ToString)
> End Try
> End Sub
>
>
> Private Sub ExecuteInsertSPWithParams(ByVal cmdCommand As
> SqlCommand)
> Try
> Using conn As New SqlConnection(dbClass.connectionString)
> conn.Open()
>
> cmdCommand.Connection = conn
> cmdCommand.CommandText =
> my.Resources.DatabaseCreationScripts.spInsertModels
> cmdCommand.ExecuteNonQuery()
>
> conn.Close()
> End Using
> Catch ex As Exception
> MessageBox.Show(ex.ToString)
> End Try
> End Sub
>
>
> Any Ideas on why I am getting this error?
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting an exception "Keyword not supported: 'provider'." =?Utf-8?B?dnZlbms=?= Microsoft ASP .NET 2 8th Oct 2005 12:05 AM
Exception while executing Stored Procedure Ramnadh Microsoft ADO .NET 1 14th Mar 2005 03:28 PM
Problem catching exception from a procedure =?Utf-8?B?RWtlbXBk?= Microsoft ADO .NET 2 6th Dec 2004 08:16 PM
Re: Sql Exception 'param name' is not a parameter for procedure'SP nam Cowboy \(Gregory A. Beamer\) [MVP] Microsoft ADO .NET 0 11th Aug 2004 04:54 PM
Problems using an "IN" keyword in a stored procedure Philip Townsend Microsoft ADO .NET 0 19th Sep 2003 11:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:08 AM.