store procedure + datareader 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()


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

Eric Lemmon

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
 

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