[store procedure] + sqldatareader problem

  • Thread starter Thread starter Agnes
  • Start date Start date
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.
 
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.
 
Back
Top