473,386 Members | 1,736 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.

store procedure + datareader problem

my simple store procedure like thiese:-
CREATE PROCEDURE dbo.companyinfo_shipper_search
@searchcode varchar(10)
as
select name
from companyheader
where code = @searchcode
GO
-------------------------------------------------------------------
my vb.net code
cmdSearch.CommandType = "dbo.companyinfo_shipper_search"
prmCompany_Code = cmdSearch.Parameters.Add("@searchcode", strCode)
prmCompany_Code.Direction = ParameterDirection.Input
prmCompany_Code.SqlDbType = SqlDbType.VarChar

Try
Dim drCompanyReader As SqlClient.SqlDataReader =
cmdSearch.ExecuteReader()
Do While drCompanyReader.Read
Console.Write(drCompanyReader.GetString(0))
Loop
........etc
I use sql analyzer to check and it really return the correct records.
However, as I use sqldatareader,
it returns error" Invalid attempt to read when no data is present".
What's wrong with my code ???
Please help.

Nov 20 '05 #1
2 947
Hi Agnes,
cmdSearch.CommandType = "dbo.companyinfo_shipper_search" It looks like the above line should be CommandText, not CommandType.
Try changing this, and be sure to set the CommandType to
CommandType.StoredProcedure (assuming that's a SP and not a table).

Does this fix it?

Take care,

Eric
"Agnes" <ag***@dynamictech.com.hk> wrote in message
news:ub**************@TK2MSFTNGP10.phx.gbl... my simple store procedure like thiese:-
CREATE PROCEDURE dbo.companyinfo_shipper_search
@searchcode varchar(10)
as
select name
from companyheader
where code = @searchcode
GO
-------------------------------------------------------------------
my vb.net code
cmdSearch.CommandType = "dbo.companyinfo_shipper_search"
prmCompany_Code = cmdSearch.Parameters.Add("@searchcode", strCode) prmCompany_Code.Direction = ParameterDirection.Input
prmCompany_Code.SqlDbType = SqlDbType.VarChar

Try
Dim drCompanyReader As SqlClient.SqlDataReader =
cmdSearch.ExecuteReader()
Do While drCompanyReader.Read
Console.Write(drCompanyReader.GetString(0))
Loop
.......etc
I use sql analyzer to check and it really return the correct records.
However, as I use sqldatareader,
it returns error" Invalid attempt to read when no data is present".
What's wrong with my code ???
Please help.

Nov 20 '05 #2
Hi Agnes,

I give you an answer bellow, but did you know there was a special newsgroup
for this kind of questions.

Adonet
<news://msnews.microsoft.com/microsoft.public.dotnet.framework.adonet>

Web interface:

<http://communities2.microsoft.com/co...s/?dg=microsof
t.public.dotnet.framework.adonet>

You can try to change this (watch typos)

\\\
cmdSearch.CommandType = CommandType.StoredProcedure
cmdSearch.Commandext = "dbo.companyinfo_shipper_search"
///

I hope this helps?

Cor
Nov 20 '05 #3

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

Similar topics

0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
2
by: Scott Natwick | last post by:
Hi, Is there a way to obtain the return code from a stored procedure? Here is what I have so far. The procedure executes, but I'm not able to find the return code from the procedure. ...
4
by: jaYPee | last post by:
I have downloaded some source code but I want this to convert the results into datagrid. dr = cmd.ExecuteReader() '**************************************** ' SHOW THE RESULTS...
10
by: Rich | last post by:
I have a stored procedure on Sql Server2k. I can fill a data table which I can append to a dataset using an ADODB recordset object which gets populated from a command object that runs the sp. I...
1
by: Joe Van Meer | last post by:
Hi all, I have an app that currently runs through 3 seperate stored procedures each returning a count of records. What I would like to do is combine these calls into one call, however I am...
7
by: Jerry | last post by:
I'm trying to execute a stored procedure in a loop while paging through database table records but the stored procedure isn't running. I get the folowing error: The component 'adodb.connection'...
6
by: c676228 | last post by:
Hi everyone, I wrote a store procedure that fetch one row data in the database based on the parameter value I entered. After I created the store procedure, the store procedure code looks like...
2
by: Krij | last post by:
Hi, I'm a student and I have the following working example that troubles me (in SQL Server 2005): CREATE PROCEDURE dbo.CustomersOrderHistory ( @Firstname varchar(7) OUTPUT) AS SELECT ...
7
by: Mark B | last post by:
How do I have a SiteMap based on the output of a stored procedure? (I want to pass a @LanguageCode parameter to it so it will display the top Menu in the appropriate language).
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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.