Error when creating dataReader

S

simon

I have:

par1 = New SqlParameter("@mediaId", SqlDbType.VarChar, 10)
par1.Value = "text"
myParams.Add(par1)

par2 = New SqlParameter("@datumStart", SqlDbType.DateTime)
par2.Value = Now()
myParams.Add(par2)

sql = "c_returnTimeSlotsHour"
Dim rdr As SqlDataReader
rdr = funkcije.createDataReader(sql, False, myParams)

Then I have my function:

Function createDataReader(ByVal sqlStr As String, Optional ByVal type As
Boolean = False, Optional ByVal myParams As Collection = Nothing) As
SqlDataReader
Dim oCmd As SqlCommand
Dim myReader As SqlDataReader
Dim param As SqlParameter
oCmd = New SqlCommand(sqlStr, createConnection)
If type = False Then
oCmd.CommandType = CommandType.StoredProcedure
If Not myParams Is Nothing Then
For Each param In myParams
oCmd.Parameters.Add(param)
Next
End If
End If
myReader = oCmd.ExecuteReader(CommandBehavior.CloseConnection)
Return myReader
End Function

The procedure:

CREATE PROCEDURE c_returnTimeSlotsHour
@mediaId as varchar(10),
@datumStart as datetime
AS

SELECT ....

When I run this, I always get an error message:

Syntax error converting the varchar value 'text' to a column of data type
int.

Why?

Thank you,
Simon
 
K

Kirby Turner

I have to guess that the problem is with the SELECT statement in your
stored procedure. My guess is that the parameter @mediaId, which
contains the value "text", is being compared to a column that is
defined as an INT data type. Check your SELECT statement and make
sure the data types match up.

-KIRBY
 

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

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top