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

Error in code?

I am having a weird error and maybe the synatax is different or something. I
use a SQL Stored Proc and pass it one param and get a return to either a
datareader or dataset. The code works fine for a datareader but the dataset
gives me a weird error. I even tried using the same SP with the two code
snippets, one works the other doesn't.
tmpSQL.SQLDB.Open()
tmpSQL.SQLCmd.CommandType = CommandType.StoredProcedure
tmpSQL.SQLCmd.CommandText = "SP_GETRECORDTEST"
SqlClient.SqlCommandBuilder.DeriveParameters(tmpSQ L.SQLCmd) <<THIS SHOWS OK
PARAMS IN DEBUG WNDW
tmpSQL.SQLCmd.Parameters(1).Value = paramNbr << SEEMS TO IGNORE THIS
Dim DS As DataSet = New DataSet
Dim DA As SqlDataAdapter = New SqlDataAdapter(tmpSQL.SQLCmd.CommandText,
tmpSQL.SQLDB)
DA.Fill(DS) <<<<<<<<<BOOM says the SP expects param and it was not passed

but this code works....
tmpSQL.SQLDB.Open()
tmpSQL.SQLCmd.CommandType = CommandType.StoredProcedure
tmpSQL.SQLCmd.CommandText = "SP_GETRECORDAGAIN"
SqlClient.SqlCommandBuilder.DeriveParameters(tmpSQ L.SQLCmd)
tmpSQL.SQLCmd.Parameters(1).Value = paramNBR
dReader = tmpSQL.SQLCmd.ExecuteReader()
dReader.Read()

I tried calling the SP_GETRECORDTEST with the datareader code and it works,
so I know the SP is OK..
I need the dataset to work for a datagrid I have, but can't get it to see
the param,
even tried a tmpSQL.SQLCmd.Parameters.Add("@tmpParam",2) with the DS
code..
did not make any difference..
Any Ideas?
Thanks JOHN


Nov 19 '05 #1
2 1366
Take a look at the constructor for your DataAdapter. You're passing the
CommandText to it. What IS the CommandText? Hint:
tmpSQL.SQLCmd.CommandText = "SP_GETRECORDTEST"
See any parameters in there?

Instead, assign the Connection to the Command, and use the Command instance
in the constructor for the DataAdapter.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Everybody picks their nose,
But some people are better at hiding it.

"John" <Jo****@aol.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...I am having a weird error and maybe the synatax is different or something.
I
use a SQL Stored Proc and pass it one param and get a return to either a
datareader or dataset. The code works fine for a datareader but the
dataset
gives me a weird error. I even tried using the same SP with the two code
snippets, one works the other doesn't.
tmpSQL.SQLDB.Open()
tmpSQL.SQLCmd.CommandType = CommandType.StoredProcedure
tmpSQL.SQLCmd.CommandText = "SP_GETRECORDTEST"
SqlClient.SqlCommandBuilder.DeriveParameters(tmpSQ L.SQLCmd) <<THIS SHOWS
OK
PARAMS IN DEBUG WNDW
tmpSQL.SQLCmd.Parameters(1).Value = paramNbr << SEEMS TO IGNORE THIS
Dim DS As DataSet = New DataSet
Dim DA As SqlDataAdapter = New SqlDataAdapter(tmpSQL.SQLCmd.CommandText,
tmpSQL.SQLDB)
DA.Fill(DS) <<<<<<<<<BOOM says the SP expects param and it was not passed

but this code works....
tmpSQL.SQLDB.Open()
tmpSQL.SQLCmd.CommandType = CommandType.StoredProcedure
tmpSQL.SQLCmd.CommandText = "SP_GETRECORDAGAIN"
SqlClient.SqlCommandBuilder.DeriveParameters(tmpSQ L.SQLCmd)
tmpSQL.SQLCmd.Parameters(1).Value = paramNBR
dReader = tmpSQL.SQLCmd.ExecuteReader()
dReader.Read()

I tried calling the SP_GETRECORDTEST with the datareader code and it
works,
so I know the SP is OK..
I need the dataset to work for a datagrid I have, but can't get it to see
the param,
even tried a tmpSQL.SQLCmd.Parameters.Add("@tmpParam",2) with the DS
code..
did not make any difference..
Any Ideas?
Thanks JOHN


Nov 19 '05 #2
Thanks Kevin... I had to add
DA.SelectCommand.Parameters.Add("@tmpParam", paramNBR)

DA.SelectCommand.CommandType = CommandType.StoredProcedure

to make it work for the dataadapter but not the datareader, it worked fine
with the original code

"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:eS**************@TK2MSFTNGP12.phx.gbl...
Take a look at the constructor for your DataAdapter. You're passing the
CommandText to it. What IS the CommandText? Hint:
tmpSQL.SQLCmd.CommandText = "SP_GETRECORDTEST"
See any parameters in there?

Instead, assign the Connection to the Command, and use the Command

instance in the constructor for the DataAdapter.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Everybody picks their nose,
But some people are better at hiding it.

"John" <Jo****@aol.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I am having a weird error and maybe the synatax is different or something.I
use a SQL Stored Proc and pass it one param and get a return to either a
datareader or dataset. The code works fine for a datareader but the
dataset
gives me a weird error. I even tried using the same SP with the two code
snippets, one works the other doesn't.
tmpSQL.SQLDB.Open()
tmpSQL.SQLCmd.CommandType = CommandType.StoredProcedure
tmpSQL.SQLCmd.CommandText = "SP_GETRECORDTEST"
SqlClient.SqlCommandBuilder.DeriveParameters(tmpSQ L.SQLCmd) <<THIS SHOWS
OK
PARAMS IN DEBUG WNDW
tmpSQL.SQLCmd.Parameters(1).Value = paramNbr << SEEMS TO IGNORE THIS
Dim DS As DataSet = New DataSet
Dim DA As SqlDataAdapter = New SqlDataAdapter(tmpSQL.SQLCmd.CommandText,
tmpSQL.SQLDB)
DA.Fill(DS) <<<<<<<<<BOOM says the SP expects param and it was not passed
but this code works....
tmpSQL.SQLDB.Open()
tmpSQL.SQLCmd.CommandType = CommandType.StoredProcedure
tmpSQL.SQLCmd.CommandText = "SP_GETRECORDAGAIN"
SqlClient.SqlCommandBuilder.DeriveParameters(tmpSQ L.SQLCmd)
tmpSQL.SQLCmd.Parameters(1).Value = paramNBR
dReader = tmpSQL.SQLCmd.ExecuteReader()
dReader.Read()

I tried calling the SP_GETRECORDTEST with the datareader code and it
works,
so I know the SP is OK..
I need the dataset to work for a datagrid I have, but can't get it to see the param,
even tried a tmpSQL.SQLCmd.Parameters.Add("@tmpParam",2) with the DS
code..
did not make any difference..
Any Ideas?
Thanks JOHN



Nov 19 '05 #3

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

Similar topics

5
by: Tony Wright | last post by:
Hi, I am having a problem installing an msi for a web site. The error message I am getting is: "The specified path 'http://mipdev05/features/Fas2' is unavailable. The Internet Information...
2
by: Gregory | last post by:
Hi, One of the disadvantages of using error handling with error codes instead of exception handling is that error codes retuned from a function can be forgotten to check thus leading to...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
16
by: Steve Jorgensen | last post by:
I'm trying to figure out if there is a way to generate standard error handlers that "know" if the calling code has an error handler in effect (On Error Goto <label> or On Error Resume Next) before...
6
by: Squirrel | last post by:
I have a command button on a subform to delete a record. The only statement in the subroutine is: DoCmd.RunCommand acCmdDeleteRecord The subform's recordsource is "select * from tblVisit order...
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
4
by: Eugene Anthony | last post by:
One problem with the code bellow is after this code conn.qDupUser p1,rs I added: set rs = nothing to test the error handling capability.
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
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: 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...
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
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,...
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...

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.