Help with error msg...

  • Thread starter Thread starter PatLaf
  • Start date Start date
P

PatLaf

Hello to all,

I need some help understanding why this is happening to
me plaase. I have the following routine written in
vb.net. I am trying to return data from a log table using
the sqlhelper dll. The query that ivestigates the
database generates the "System.InvalidCastException:
Object must implement IConvertible. at
System.Data.SqlClient.SqlCommand.ExecuteReader" .....

Here is the code that uses the ms provided application
block

' SqlDataReader that will hold the returned results

Dim ds As System.Data.DataSet = Nothing
' SqlConnection that will be used to execute the
sql commands
Dim connection As SqlConnection = Nothing

Try
Try
connection = GetConnection(m_DbConnStr)
Dim g As System.Guid

With m_oSqlHelper
.ClearParam(m_oParms)
.AddParam(m_oParms, "@Start_Date",
SqlDbType.DateTime, ParameterDirection.Input, 8,
Convert.ToDateTime(Me.txtStartDateTime.Text.ToString))
System.Diagnostics.Debug.WriteLine
(Me.txtStartDateTime.Text.ToString)
.AddParam(m_oParms, "@End_Date",
SqlDbType.DateTime, ParameterDirection.Input, 8,
Convert.ToDateTime(Me.txtEndDateTime.Text.ToString))
System.Diagnostics.Debug.WriteLine
(Me.txtEndDateTime.Text.ToString)
g = New System.Guid
(Me.ddlMachine.SelectedValue.ToString)
System.Diagnostics.Debug.WriteLine
(g.ToString)
.AddParam(m_oParms, "@Machine_Id",
SqlDbType.Char, ParameterDirection.Input, 16, g)
g = New System.Guid
(Me.ddlBusinessUnits.SelectedValue.ToString)
System.Diagnostics.Debug.WriteLine
(g.ToString)
.AddParam(m_oParms, "@Bu_ID",
SqlDbType.Char, ParameterDirection.Input, 16, g)
g = New System.Guid
(Me.ddlTechnician.SelectedValue.ToString)
System.Diagnostics.Debug.WriteLine
(g.ToString)
.AddParam(m_oParms, "@Users_ID_Id",
SqlDbType.Char, ParameterDirection.Input, 16, g)
g = New System.Guid
(Me.ddlMalfunctionTypes.SelectedValue.ToString)
System.Diagnostics.Debug.WriteLine
(g.ToString)
.AddParam
(m_oParms, "@malfunction_ID", SqlDbType.Char,
ParameterDirection.Input, 16, g)
End With

ds = m_oSqlHelper.ExecuteDataset
(connection,
CommandType.StoredProcedure, "sp_Get_OEEData_By_Date",
m_oParms)

Catch ex As Exception
With lblError
'.Text = "The connection with the
database can´t be established"
.Text = ex.ToString
.Visible = True
.Enabled = True
Exit Sub
End With

End Try

'bind datareader to datagrid
With Me.oDgReport
.DataSource = ds.Tables(0)
.DataBind()
End With

Catch ex As Exception
Dim errMessage As String = ""
Dim tempException As Exception = ex

While (Not tempException Is Nothing)
errMessage += tempException.Message +
Environment.NewLine + Environment.NewLine
tempException =
tempException.InnerException
End While

Finally
If Not ds Is Nothing Then
CType(ds, IDisposable).Dispose()
End If

If Not connection Is Nothing Then
CType(connection, IDisposable).Dispose()
End If
End Try
End Sub


The query works in qry analyzer. If I stop the code and
grab the sql syntax and run it in query analyzer it works
as advertised. It just won't run from .Net....any ideas?

Thanks in advance,
Pat
 
Hello Pat,

Thanks for your post. Based on my experience, this exception means that
there is a conversion problem and the SqlClient managed provider does not
support IConvertable in order to perform the conversion. So, what this
error indicates is that when the query was executed one (or more) parameter
has failed to bind with the provided data type. To narrow down the problem,
I suggest that you can create a new Stored Procedure without any parameter
and see if it works. And then you can add the parameters one by one to the
Stored Procedure to check which one causes the problem.

Hope this helps.

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top