Object must implement IConvertible.

Discussion in 'ASP .Net' started by =?Utf-8?B?VGltOjouLg==?=, Dec 15, 2004.

  1. Can someone please tell me why I keep getting the following error! I can't
    seem to find out what is causeing the problem and would really appritiate any
    assistance!

    Thanks!
    ... ERROR

    Exception Details: System.InvalidCastException: Object must implement
    IConvertible.

    Source Error:


    Line 230:
    Line 231:
    Line 232: Dim myReader As SqlDataReader = cmd.ExecuteReader()
    Line 233:
    Line 234: myReader.Read()


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


    Dim myReader As SqlDataReader = cmd.ExecuteReader()

    myReader.Read()
    PageID = cmd.Parameters("@PageID").Value
    myReader.Close()

    Myconn.Close()

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

    End Sub
    =?Utf-8?B?VGltOjouLg==?=, Dec 15, 2004
    #1
    1. Advertising

  2. Hi Tim,

    I'm a little confused, as your error message includes the top and bottom
    lines of the snippet below, but not the second line, which I believe is
    producing the error:

    > myReader.Read()
    > PageID = cmd.Parameters("@PageID").Value
    > myReader.Close()


    I'm not sure what the exception means in this context, but I can tell you
    that you have to close your DataReader before you can access output
    parameters from it.

    --
    HTH,
    Kevin Spencer
    ..Net Developer
    Microsoft MVP
    Neither a follower
    nor a lender be.

    "Tim::.." <myatix_at_hotmail.com> wrote in message
    news:...
    > Can someone please tell me why I keep getting the following error! I can't
    > seem to find out what is causeing the problem and would really appritiate

    any
    > assistance!
    >
    > Thanks!
    > .. ERROR
    >
    > Exception Details: System.InvalidCastException: Object must implement
    > IConvertible.
    >
    > Source Error:
    >
    >
    > Line 230:
    > Line 231:
    > Line 232: Dim myReader As SqlDataReader = cmd.ExecuteReader()
    > Line 233:
    > Line 234: myReader.Read()
    >
    >
    > .. 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
    >
    >
    > Dim myReader As SqlDataReader = cmd.ExecuteReader()
    >
    > myReader.Read()
    > PageID = cmd.Parameters("@PageID").Value
    > myReader.Close()
    >
    > Myconn.Close()
    >
    > 'Rebind the DataGrid
    > DGPages.EditItemIndex = -1
    > BindData()
    > End If
    >
    > End Sub
    Kevin Spencer, Dec 15, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Leon Shaw
    Replies:
    5
    Views:
    873
    Leon Shaw
    Jul 29, 2003
  2. Bob Frasca

    Error:Object must implement IConvertible

    Bob Frasca, Jul 29, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    476
    Bob Frasca
    Jul 29, 2003
  3. =?Utf-8?B?VGltOjouLg==?=

    Error: Object must implement IConvertible

    =?Utf-8?B?VGltOjouLg==?=, Dec 14, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,126
    Guest
    Dec 14, 2004
  4. Replies:
    4
    Views:
    3,294
  5. Replies:
    2
    Views:
    1,292
Loading...

Share This Page