473,396 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Incorrect syntax near Create Sproc

I wrote a stored procedure that runs fine when I execute from SQL 2005
Management Studio, and runs ok when I step into it from VS2005. Both return a
value of 0, drop, create & populate the table.

But when I run it inline in the vb.net code, I get an error:

+ ex {"Incorrect syntax near 'spCreateRank1'."}
System.Data.SqlClient.SqlException

No Inner Exception or other useful information I can see.

************************************************** ****
-- start sproc
USE [dbname]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spCreateRank1]
@outputTable varchar(32)
AS
BEGIN
SET NOCOUNT ON
-- Drop table if exists
IF OBJECT_ID(N'tblRank1', N'U') IS NOT NULL
DROP TABLE [dbo].[tblRank1]

-- Copy certain fields from all rows of output_ table into tblRank1 table
EXEC( 'SELECT firstname,lastname,city,[state],case_number,countyname
INTO tblRank1 FROM output_' + @outputTable )

END --sproc

************************************************** *******
'vb.net code

Dim Conn2 As New SqlConnection(strSqlConn)
Dim sqlCmd As SqlCommand = New SqlCommand("spCreateRank1", Conn2)

sqlCmd.CommandText = "spCreateRank1"

sqlCmd.Parameters.Add(New SqlParameter("@outputTable", SqlDbType.VarChar,
32)).Value = strView

Dim iRows As Integer

If intRank = 1 Then

Try

If Conn2.State = ConnectionState.Closed Then Conn2.Open()

iRows = sqlCmd.ExecuteNonQuery

If Conn2.State = ConnectionState.Open Then Conn2.Close()

Catch ex As SqlException

DisplaySqlExceptionInfo(ex)

End Try

************************************************** *******

Thanks for any advice!
May 8 '07 #1
1 3345
Oops - I forgot to set CommandType. Now it works.

sqlCmd.CommandType = CommandType.StoredProcedure

"Bil Click" wrote:
I wrote a stored procedure that runs fine when I execute from SQL 2005
Management Studio, and runs ok when I step into it from VS2005. Both return a
value of 0, drop, create & populate the table.

But when I run it inline in the vb.net code, I get an error:

+ ex {"Incorrect syntax near 'spCreateRank1'."}
System.Data.SqlClient.SqlException

No Inner Exception or other useful information I can see.

************************************************** ****
-- start sproc
USE [dbname]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spCreateRank1]
@outputTable varchar(32)
AS
BEGIN
SET NOCOUNT ON
-- Drop table if exists
IF OBJECT_ID(N'tblRank1', N'U') IS NOT NULL
DROP TABLE [dbo].[tblRank1]

-- Copy certain fields from all rows of output_ table into tblRank1 table
EXEC( 'SELECT firstname,lastname,city,[state],case_number,countyname
INTO tblRank1 FROM output_' + @outputTable )

END --sproc

************************************************** *******
'vb.net code

Dim Conn2 As New SqlConnection(strSqlConn)
Dim sqlCmd As SqlCommand = New SqlCommand("spCreateRank1", Conn2)

sqlCmd.CommandText = "spCreateRank1"

sqlCmd.Parameters.Add(New SqlParameter("@outputTable", SqlDbType.VarChar,
32)).Value = strView

Dim iRows As Integer

If intRank = 1 Then

Try

If Conn2.State = ConnectionState.Closed Then Conn2.Open()

iRows = sqlCmd.ExecuteNonQuery

If Conn2.State = ConnectionState.Open Then Conn2.Close()

Catch ex As SqlException

DisplaySqlExceptionInfo(ex)

End Try

************************************************** *******

Thanks for any advice!

May 8 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jeff Magouirk | last post by:
Dear Group, I am trying to create a view and keep getting the Incorrect syntax near the keyword 'Declare'" error. Here is the code I am writing. Create view fixed_airs (sid, fad_a2, fad_a3)...
3
by: teddysnips | last post by:
In the script below is the DDL to create some tables and a UDF. What I'm interested in is the UDF at the end. Specifically, these few lines: --CLOSE OTRate --DEALLOCATE OTRate ELSE --...
1
by: Sandesh | last post by:
Hello All, Me saying " has any body come across such error would be underestimating". Well I am getting a very peculiar and unique error "Line 1: Incorrect syntax near 'Actions'." ...
1
by: iporter | last post by:
In the following code, the two Response.Write statements output exactly the same - I can copy and paste both into Query Analyzer, and run them fine. However, if I comment out line 3, the...
1
by: mabubakarpk | last post by:
HI. I am using SQL Server 2000. I generate a script of some table from EmpDB database when I run script in query analyzer it return error "Incorrect syntax near 'COLLATE'." Scripts is ...
0
by: roamnet | last post by:
hi i created database file with .mdf extention ,sql server as a source and use grid view to display data there're no problem in data retrieve and display,but i want to edit it or insert new...
10
by: arial | last post by:
Hi, I am getting this error message: Incorrect syntax near the keyword 'where'. Description: An unhandled exception occurred during the execution of the current web request. Please review...
1
by: karenkksh | last post by:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. ...
1
by: asf93555 | last post by:
Running under SQL2000 I can not get an INSTEAD trigger to function. I've even copied the example directl from books online - no joy . . . Server: Msg 170, Level 15, State 1, Procedure...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.