Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Error: Object must implement IConvertible

Reply
Thread Tools

Error: Object must implement IConvertible

 
 
=?Utf-8?B?VGltOjouLg==?=
Guest
Posts: n/a
 
      12-14-2004
Hi can someone please help me with the following error!

I keep getting:

ERROR:
System.InvalidCastException: Object must implement IConvertible.

Line 231: PageID = cmd.Parameters("@PageID").Value
Line 232:
Line 233: Dim myReader As SqlDataReader = cmd.ExecuteReader()
Line 234: myReader.Read()
Line 235:

I would be really grateful if someone could tell me why this might be
happening!

Thanks

... CODE ..

Sub DGPages_Insert(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
If e.CommandName = "Insert" Then
Dim modDate As String
Dim dtNow As DateTime = DateTime.Now
Dim description As String
Dim txtdescription As TextBox
Dim title As String
Dim txtTitle As TextBox
Dim PageID As Integer

Dim strSQL As String
modDate = dtNow.Date
'Read in the values of the TextBoxes


txtdescription = e.Item.FindControl("add_description")
description = txtdescription.Text
txtTitle = e.Item.FindControl("add_Title")
title = txtTitle.Text



'Create the appropriate SQL statement
Dim Myconn As New
SqlConnection(ConfigurationSettings.AppSettings("s trConn"))
Dim cmd As New SqlCommand("PageAdd", Myconn)
cmd.CommandType = CommandType.StoredProcedure

Myconn.Open()

' Add Parameters to the SQL query
Dim objModDate, objDescription, objTitle, objPageID, objOffice
As SqlParameter
objModDate = cmd.Parameters.Add("@modDate", SqlDbType.DateTime)
objDescription = cmd.Parameters.Add("@description",
SqlDbType.NVarChar)
objTitle = cmd.Parameters.Add("@title", SqlDbType.NVarChar)
objPageID = cmd.Parameters.Add("@PageID", SqlDbType.Int)

objModDate.Direction = ParameterDirection.Input
objDescription.Direction = ParameterDirection.Input
objTitle.Direction = ParameterDirection.Input
cmd.Parameters("@PageID").Direction = ParameterDirection.Output

objModDate.Value = modDate
objDescription.Value = txtdescription
objTitle.Value = txtTitle
PageID = cmd.Parameters("@PageID").Value

Dim myReader As SqlDataReader = cmd.ExecuteReader()
myReader.Read()

myReader.Close()

Myconn.Close()

'Rebind the DataGrid
DGPages.EditItemIndex = -1
BindData()
End If

End Sub
 
Reply With Quote
 
 
 
 
Guest
Posts: n/a
 
      12-14-2004
Since your @PageID is an output parameter, you should put
PageID = cmd.Parameters("@PageID").Value after
any SqlCommand execute statement such as ExecuteNonQuery,
or ExecuteReader, or ExecuteScalar rather than before
those codes.

Hope it's helpful to you.

Elton
http://www.velocityreviews.com/forums/(E-Mail Removed)


>-----Original Message-----
>Hi can someone please help me with the following error!
>
>I keep getting:
>
>ERROR:
>System.InvalidCastException: Object must implement

IConvertible.
>
>Line 231: PageID = cmd.Parameters

("@PageID").Value
>Line 232:
>Line 233: Dim myReader As SqlDataReader =

cmd.ExecuteReader()
>Line 234: myReader.Read()
>Line 235:
>
>I would be really grateful if someone could tell me why

this might be
>happening!
>
>Thanks
>
>... CODE ..
>
> Sub DGPages_Insert(ByVal sender As Object, ByVal e As
>DataGridCommandEventArgs)
> If e.CommandName = "Insert" Then
> Dim modDate As String
> Dim dtNow As DateTime = DateTime.Now
> Dim description As String
> Dim txtdescription As TextBox
> Dim title As String
> Dim txtTitle As TextBox
> Dim PageID As Integer
>
> Dim strSQL As String
> modDate = dtNow.Date
> 'Read in the values of the TextBoxes
>
>
> txtdescription = e.Item.FindControl

("add_description")
> description = txtdescription.Text
> txtTitle = e.Item.FindControl("add_Title")
> title = txtTitle.Text
>
>
>
> 'Create the appropriate SQL statement
> Dim Myconn As New
>SqlConnection(ConfigurationSettings.AppSettings

("strConn"))
> Dim cmd As New SqlCommand("PageAdd", Myconn)
> cmd.CommandType = CommandType.StoredProcedure
>
> Myconn.Open()
>
> ' Add Parameters to the SQL query
> Dim objModDate, objDescription, objTitle,

objPageID, objOffice
>As SqlParameter
> objModDate = cmd.Parameters.Add("@modDate",

SqlDbType.DateTime)
> objDescription = cmd.Parameters.Add

("@description",
>SqlDbType.NVarChar)
> objTitle = cmd.Parameters.Add("@title",

SqlDbType.NVarChar)
> objPageID = cmd.Parameters.Add("@PageID",

SqlDbType.Int)
>
> objModDate.Direction =

ParameterDirection.Input
> objDescription.Direction =

ParameterDirection.Input
> objTitle.Direction = ParameterDirection.Input
> cmd.Parameters("@PageID").Direction =

ParameterDirection.Output
>
> objModDate.Value = modDate
> objDescription.Value = txtdescription
> objTitle.Value = txtTitle
> PageID = cmd.Parameters("@PageID").Value
>
> Dim myReader As SqlDataReader =

cmd.ExecuteReader()
> myReader.Read()
>
> myReader.Close()
>
> Myconn.Close()
>
> 'Rebind the DataGrid
> DGPages.EditItemIndex = -1
> BindData()
> End If
>
> End Sub
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Object Must Implement IConvertible is a BUG non solved? lcorrias@yahoo.com ASP .Net 2 08-10-2006 03:09 AM
ERROR: Object must implement IConvertible. charleswesley@gmail.com ASP .Net 4 10-02-2005 09:56 AM
Object must implement IConvertible. =?Utf-8?B?VGltOjouLg==?= ASP .Net 1 12-15-2004 02:06 PM
Error:Object must implement IConvertible Bob Frasca ASP .Net 1 07-29-2003 04:04 PM
ERROR:Object must implement IConvertible. Leon Shaw ASP .Net 5 07-29-2003 02:10 PM



Advertisments