[store procedure] + sqldatareader problem

A

Agnes

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(CommandBehavior.SequentialAccess)


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.
 
M

Marina

Why are you passing in CommandBehavior.SequentialAccess? That might be the
problem - try taking you out, you probably don't need it anyway since it
doesn't look like you are returning large binary data.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top