473,387 Members | 1,455 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,387 software developers and data experts.

ado.net data access error help

Hi Everyone,
Please help me on this one. I have the following function:
Public Sub SearchFor(ByRef mType As Module1.SearchForType, ByRef mValue As
String)
On Error GoTo Err_Handler
Dim Proc As String
Dim conStr as string = "Integrated Security=SSPI;Persist Security
Info=False;Initial Catalog=Inventory;Data Source=SQLSERVER;"
Dim con as SqlConnection = new SqlConnection(conStr)
Dim cmd as SqlCommand
Select Case mType
Case Module1.SearchForType.ByBarCode
cmd = new SqlCommand("nf_GetInventoryItem", con)
cmd.Parameters.Add("@BarCodeId", sqldbtype.Int).Value = Val(CStr(mValue))
Case Module1.SearchForType.ByProductName
cmd = new SqlCommand("nf_GetInventoryByProductName", con)
cmd.Parameters.Add("@ProductName", sqldbtype.NVarChar, 25 ).Value = mValue
Case Module1.SearchForType.ByModelNumber
cmd = new SqlCommand("nf_GetInventoryByModelNumber", con)
cmd.Parameters.Add("@ModelNumber", sqldbtype.NVarChar, 30 ).Value = mValue
End Select
Dim ds as DataSet = new DataSet("SearchForQuery")
dim da as SqlDataAdapter
da = new SqlDataAdapter()
da.SelectCommand = cmd
da.Fill(ds)
PopulateGrid(ds)
Me.Show()
Exit Sub
Err_Handler:
MsgBox(Err.Number & ": " & Err.Description)
End Sub

The problem is that when the code gets to the da.Fill(ds) command, I get a
"Line 1: Incorrect syntax near 'nf_GetInventoryByProductName'." Error. I can
run the query in Studio .Net or Sql Server Enterprise manager and it works
just fine. I'm also feeding the parameter a value that is in the database. I
can run any of the three stored procedures within this function and will get
the same error message(except the sp name is changed to reflect the sp that
was selected). Does this code right? I'm new to the ADO.Net and little things
like this is driving me nuts :( Thanks for any suggestions that you can offer.
Michael

Nov 21 '05 #1
2 1385
Hi,

Two things. First I would get rid of the on error goto and
switch to using a try catch block. Second You never set the command type to
stored procedure

cmd = new SqlCommand("nf_GetInventoryItem", con)
cmd.commandtype=commandtype.storedprocedure

http://msdn.microsoft.com/library/de...dtypetopic.asp

Try catch info
http://msdn.microsoft.com/library/de...tchfinally.asp

http://msdn.microsoft.com/library/de...tchfinally.asp

Ken
------------------
"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:10**********************************@microsof t.com...
Hi Everyone,
Please help me on this one. I have the following function:
Public Sub SearchFor(ByRef mType As Module1.SearchForType, ByRef mValue As
String)
On Error GoTo Err_Handler
Dim Proc As String
Dim conStr as string = "Integrated Security=SSPI;Persist Security
Info=False;Initial Catalog=Inventory;Data Source=SQLSERVER;"
Dim con as SqlConnection = new SqlConnection(conStr)
Dim cmd as SqlCommand
Select Case mType
Case Module1.SearchForType.ByBarCode
cmd = new SqlCommand("nf_GetInventoryItem", con)
cmd.Parameters.Add("@BarCodeId", sqldbtype.Int).Value = Val(CStr(mValue))
Case Module1.SearchForType.ByProductName
cmd = new SqlCommand("nf_GetInventoryByProductName", con)
cmd.Parameters.Add("@ProductName", sqldbtype.NVarChar, 25 ).Value = mValue
Case Module1.SearchForType.ByModelNumber
cmd = new SqlCommand("nf_GetInventoryByModelNumber", con)
cmd.Parameters.Add("@ModelNumber", sqldbtype.NVarChar, 30 ).Value = mValue
End Select
Dim ds as DataSet = new DataSet("SearchForQuery")
dim da as SqlDataAdapter
da = new SqlDataAdapter()
da.SelectCommand = cmd
da.Fill(ds)
PopulateGrid(ds)
Me.Show()
Exit Sub
Err_Handler:
MsgBox(Err.Number & ": " & Err.Description)
End Sub

The problem is that when the code gets to the da.Fill(ds) command, I get a
"Line 1: Incorrect syntax near 'nf_GetInventoryByProductName'." Error. I
can
run the query in Studio .Net or Sql Server Enterprise manager and it works
just fine. I'm also feeding the parameter a value that is in the database. I
can run any of the three stored procedures within this function and will get
the same error message(except the sp name is changed to reflect the sp that
was selected). Does this code right? I'm new to the ADO.Net and little
things
like this is driving me nuts :( Thanks for any suggestions that you can
offer.
Michael
Nov 21 '05 #2
Hi Ken,
Thanks for the reply. Last night I found the solution after a little more
reading(I've done alot of reading the last few months, lol). One more
question, is there something like the Refresh method on the Parameter
collection like there was in ADO. It was alittle easier to write the
parameters before. Thanks again for the reply.
Michael Lee
"Ken Tucker [MVP]" wrote:
Hi,

Two things. First I would get rid of the on error goto and
switch to using a try catch block. Second You never set the command type to
stored procedure

cmd = new SqlCommand("nf_GetInventoryItem", con)
cmd.commandtype=commandtype.storedprocedure

http://msdn.microsoft.com/library/de...dtypetopic.asp

Try catch info
http://msdn.microsoft.com/library/de...tchfinally.asp

http://msdn.microsoft.com/library/de...tchfinally.asp

Ken
------------------
"Michael" <Mi*****@discussions.microsoft.com> wrote in message
news:10**********************************@microsof t.com...
Hi Everyone,
Please help me on this one. I have the following function:
Public Sub SearchFor(ByRef mType As Module1.SearchForType, ByRef mValue As
String)
On Error GoTo Err_Handler
Dim Proc As String
Dim conStr as string = "Integrated Security=SSPI;Persist Security
Info=False;Initial Catalog=Inventory;Data Source=SQLSERVER;"
Dim con as SqlConnection = new SqlConnection(conStr)
Dim cmd as SqlCommand
Select Case mType
Case Module1.SearchForType.ByBarCode
cmd = new SqlCommand("nf_GetInventoryItem", con)
cmd.Parameters.Add("@BarCodeId", sqldbtype.Int).Value = Val(CStr(mValue))
Case Module1.SearchForType.ByProductName
cmd = new SqlCommand("nf_GetInventoryByProductName", con)
cmd.Parameters.Add("@ProductName", sqldbtype.NVarChar, 25 ).Value = mValue
Case Module1.SearchForType.ByModelNumber
cmd = new SqlCommand("nf_GetInventoryByModelNumber", con)
cmd.Parameters.Add("@ModelNumber", sqldbtype.NVarChar, 30 ).Value = mValue
End Select
Dim ds as DataSet = new DataSet("SearchForQuery")
dim da as SqlDataAdapter
da = new SqlDataAdapter()
da.SelectCommand = cmd
da.Fill(ds)
PopulateGrid(ds)
Me.Show()
Exit Sub
Err_Handler:
MsgBox(Err.Number & ": " & Err.Description)
End Sub

The problem is that when the code gets to the da.Fill(ds) command, I get a
"Line 1: Incorrect syntax near 'nf_GetInventoryByProductName'." Error. I
can
run the query in Studio .Net or Sql Server Enterprise manager and it works
just fine. I'm also feeding the parameter a value that is in the database. I
can run any of the three stored procedures within this function and will get
the same error message(except the sp name is changed to reflect the sp that
was selected). Does this code right? I'm new to the ADO.Net and little
things
like this is driving me nuts :( Thanks for any suggestions that you can
offer.
Michael

Nov 21 '05 #3

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

Similar topics

7
by: Jack | last post by:
Hi, I am trying to test a sql statement in Access which gives me the error as stated in the heading. The sql statement is built as a part of asp login verification, where the userid and password...
32
by: Neil Ginsberg | last post by:
We're using SQL Server 7 with an Access 2000 MDB as a front end with ODBC linked tables. I recently created a new set of tables for the app, and users are complaining that unsaved data is being...
1
by: Dan | last post by:
Could someone please help me with auto importing a series of data files into an Access table. I tried to follow code given below in a previous messagebut i'm getting error messages. Here's my...
3
by: Christopher Koh | last post by:
how do you stop Access from saving any changed data in your tables and queries? like i just add or change data on the table/query tables,then click on X (exit)because i have no intention of saving...
2
by: sympatico | last post by:
hi, pls help me slove this problem. i am a newbie in using asp.net and SQL server 2000 and my problem for now is to pass data to a textfile and i have fail to do so. the way i did it was i used...
3
by: developer | last post by:
Hi All, I am lil confused with different ways of asynchronous data access. My understanding is that, asynchronous data access frees up a thread instead of engaging it while a stored proc is...
10
by: aaronrm | last post by:
I have a real simple cross-tab query that I am trying to sum on as the action but I am getting the "data type mismatch criteria expression" error. About three queries up the food chain from this...
5
by: trig | last post by:
Please help! I am an ICT teacher at a secondary school and my year 12 (AS Level) group need to create a website where data can be sent from a form to a Microsoft Access database. I am trying...
10
by: hugh welford | last post by:
Hi Have just installed IIS7 on Vista and am trying to access a .mdb file through ASP. Getting server error. I think the problem is in the file permission. Under XP Pro/IIS6 is used to have to...
4
by: Rick | last post by:
I've moved code from a stage machine to the production machine, exact same code works fine on the stage machine, they are both windows 2003 servers, I'm getting a "Cannot generate SSPI context"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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...
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,...

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.