473,772 Members | 3,731 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Sql Client.SqlExcep tion

No Inner Exception or other useful information I can see.

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

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

END --sproc

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

Dim Conn2 As New SqlConnection(s trSqlConn)
Dim sqlCmd As SqlCommand = New SqlCommand("spC reateRank1", Conn2)

sqlCmd.CommandT ext = "spCreateRa nk1"

sqlCmd.Paramete rs.Add(New SqlParameter("@ outputTable", SqlDbType.VarCh ar,
32)).Value = strView

Dim iRows As Integer

If intRank = 1 Then

Try

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

iRows = sqlCmd.ExecuteN onQuery

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

Catch ex As SqlException

DisplaySqlExcep tionInfo(ex)

End Try

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

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

sqlCmd.CommandT ype = CommandType.Sto redProcedure

"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.Sql Client.SqlExcep tion

No Inner Exception or other useful information I can see.

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

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

END --sproc

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

Dim Conn2 As New SqlConnection(s trSqlConn)
Dim sqlCmd As SqlCommand = New SqlCommand("spC reateRank1", Conn2)

sqlCmd.CommandT ext = "spCreateRa nk1"

sqlCmd.Paramete rs.Add(New SqlParameter("@ outputTable", SqlDbType.VarCh ar,
32)).Value = strView

Dim iRows As Integer

If intRank = 1 Then

Try

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

iRows = sqlCmd.ExecuteN onQuery

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

Catch ex As SqlException

DisplaySqlExcep tionInfo(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
14195
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) as Declare @sid int, @fad_a2 int,
3
6170
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 -- @NumRecords <= 0 If I uncommment CLOSE and DEALLOCATE and check the syntax I get a
1
11252
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'." Explaining you the scene is the following Stored Proc.
1
2356
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 assignment of "SELECT T..." to the variable query, the last line produces the error: Line 1: Incorrect syntax near '<'. Many thanks in advance for any explanation - the problem is tearing my hair out!! Iain
1
10414
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 ****************************************************** if exists (select * from dbo.sysobjects where id = object_id(N'.') and OBJECTPROPERTY(id, N'IsUserTable') = 1) drop table . GO
0
8329
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 records there is an error "Incorrect syntax near '-'. Must declare the scalar variable "@UserName". I worked out in design view,code is automatically generated.Iam not able fix the error. Iam working with Visual Web Developer-2005 Express Edition
10
3426
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 the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'where'. Source Error:
1
6269
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. Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'user'. Source Error: Line 35: MyAdapter1 = new SqlDataAdapter(MyCommand1); Line 36: MyDataSet1 = new DataSet(); Line 37: ...
1
3198
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 IO_Trig_INS_Employee, Line 2 Line 2: Incorrect syntax near 'INSTEAD'. CREATE TABLE Person ( SSN char(11) PRIMARY KEY, Name nvarchar(100), Address nvarchar(100),
0
9620
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10104
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8934
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.