Must implement IConvertable?!

Discussion in 'ASP .Net' started by Brian Henry, Jul 14, 2004.

  1. Brian Henry

    Brian Henry Guest

    Hi, I am doing the following stored procedure

    CREATE PROCEDURE [dbo].[RSMN_AddMessage]
    @sender varchar(50),
    @subject varchar(400),
    @messagebody text,
    @hasAttachments bit,
    @sentTime DateTime
    AS


    insert into messages(sendername, subject, messagebody, hasattachments,
    senttime)
    values (@sender, @subject, @messagebody, @hasAttachments, @sentTime)

    select scope_identity()
    GO

    which, the ID field of it (MessageID bigint) is a bigint data type in SQL
    Server 2000... when I execute this in query anaylzer it works perfectly and
    returns a ID number for the identity column MessageID... but when I run this
    in VB.NET with this code

    database.OpenConnection()
    MessageID = CInt(cmdAddMessage.ExecuteScalar())
    database.CloseConnection()

    it comes back with this on my asp.net page as the error...


    Server Error in '/' Application.


    Object must implement IConvertible.
    Description: An unhandled exception occurred during the execution of the
    current web request. Please review the stack trace for more information
    about the error and where it originated in the code.

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

    Source Error:

    Line 88: database.OpenConnection()
    Line 89:
    Line 90: MessageID = CInt(cmdAddMessage.ExecuteScalar())Line 91:
    Line 92: database.CloseConnection()


    Source File: c:\inetpub\wwwroot\SecurePages\Compose.aspx.vb Line: 90

    Stack Trace:

    [InvalidCastException: Object must implement IConvertible.]
    System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
    cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
    System.Data.SqlClient.SqlCommand.ExecuteScalar()
    hpsql.Compose.btnSendMessage_Click(Object sender, ImageClickEventArgs e)
    in c:\inetpub\wwwroot\SecurePages\Compose.aspx.vb:90
    System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)

    System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.Ra
    isePostBackEvent(String eventArgument)
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    sourceControl, String eventArgument)
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    System.Web.UI.Page.ProcessRequestMain() +1277



    Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET
    Version:1.1.4322.573



    what in the world is causing this? thanks! i also tried direct casting to
    Int64 and Int32 and both failed the same way... BigInt should be a 64bit
    integer from what ive heard...
     
    Brian Henry, Jul 14, 2004
    #1
    1. Advertising

  2. I tested it using a String type to receive the result of your stored
    procedure and it worked. You may want to try that.

    Telmo Sampaio

    "Brian Henry" <> wrote in message
    news:...
    > Hi, I am doing the following stored procedure
    >
    > CREATE PROCEDURE [dbo].[RSMN_AddMessage]
    > @sender varchar(50),
    > @subject varchar(400),
    > @messagebody text,
    > @hasAttachments bit,
    > @sentTime DateTime
    > AS
    >
    >
    > insert into messages(sendername, subject, messagebody, hasattachments,
    > senttime)
    > values (@sender, @subject, @messagebody, @hasAttachments, @sentTime)
    >
    > select scope_identity()
    > GO
    >
    > which, the ID field of it (MessageID bigint) is a bigint data type in SQL
    > Server 2000... when I execute this in query anaylzer it works perfectly

    and
    > returns a ID number for the identity column MessageID... but when I run

    this
    > in VB.NET with this code
    >
    > database.OpenConnection()
    > MessageID = CInt(cmdAddMessage.ExecuteScalar())
    > database.CloseConnection()
    >
    > it comes back with this on my asp.net page as the error...
    >
    >
    > Server Error in '/' Application.
    >
    >
    > Object must implement IConvertible.
    > Description: An unhandled exception occurred during the execution of the
    > current web request. Please review the stack trace for more information
    > about the error and where it originated in the code.
    >
    > Exception Details: System.InvalidCastException: Object must implement
    > IConvertible.
    >
    > Source Error:
    >
    > Line 88: database.OpenConnection()
    > Line 89:
    > Line 90: MessageID = CInt(cmdAddMessage.ExecuteScalar())Line 91:
    > Line 92: database.CloseConnection()
    >
    >
    > Source File: c:\inetpub\wwwroot\SecurePages\Compose.aspx.vb Line: 90
    >
    > Stack Trace:
    >
    > [InvalidCastException: Object must implement IConvertible.]
    > System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
    > cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
    > System.Data.SqlClient.SqlCommand.ExecuteScalar()
    > hpsql.Compose.btnSendMessage_Click(Object sender, ImageClickEventArgs

    e)
    > in c:\inetpub\wwwroot\SecurePages\Compose.aspx.vb:90
    > System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
    >
    >

    System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.Ra
    > isePostBackEvent(String eventArgument)
    > System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    > sourceControl, String eventArgument)
    > System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    > System.Web.UI.Page.ProcessRequestMain() +1277
    >
    >
    >
    > Version Information: Microsoft .NET Framework Version:1.1.4322.573;

    ASP.NET
    > Version:1.1.4322.573
    >
    >
    >
    > what in the world is causing this? thanks! i also tried direct casting to
    > Int64 and Int32 and both failed the same way... BigInt should be a 64bit
    > integer from what ive heard...
    >
    >
     
    Telmo Sampaio, Jul 14, 2004
    #2
    1. Advertising

  3. Brian Henry

    Brian Henry Guest

    tried it like this

    MessageID = DirectCast(cmdAddMessage.ExecuteScalar(), Int64)

    still same error



    "William Ryan eMVP" <> wrote in message
    news:...
    > try the cast using Int64. If I remember correctly, that's what BigInt

    maps
    > back to.
    >
    > --
    >
    > W.G. Ryan, eMVP
    >
    > Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
    > Let Microsoft know!
    > https://www.windowsembeddedeval.com/community/newsgroups
    > "Brian Henry" <> wrote in message
    > news:...
    > > Hi, I am doing the following stored procedure
    > >
    > > CREATE PROCEDURE [dbo].[RSMN_AddMessage]
    > > @sender varchar(50),
    > > @subject varchar(400),
    > > @messagebody text,
    > > @hasAttachments bit,
    > > @sentTime DateTime
    > > AS
    > >
    > >
    > > insert into messages(sendername, subject, messagebody, hasattachments,
    > > senttime)
    > > values (@sender, @subject, @messagebody, @hasAttachments, @sentTime)
    > >
    > > select scope_identity()
    > > GO
    > >
    > > which, the ID field of it (MessageID bigint) is a bigint data type in

    SQL
    > > Server 2000... when I execute this in query anaylzer it works perfectly

    > and
    > > returns a ID number for the identity column MessageID... but when I run

    > this
    > > in VB.NET with this code
    > >
    > > database.OpenConnection()
    > > MessageID = CInt(cmdAddMessage.ExecuteScalar())
    > > database.CloseConnection()
    > >
    > > it comes back with this on my asp.net page as the error...
    > >
    > >
    > > Server Error in '/' Application.
    > >
    > >
    > > Object must implement IConvertible.
    > > Description: An unhandled exception occurred during the execution of the
    > > current web request. Please review the stack trace for more information
    > > about the error and where it originated in the code.
    > >
    > > Exception Details: System.InvalidCastException: Object must implement
    > > IConvertible.
    > >
    > > Source Error:
    > >
    > > Line 88: database.OpenConnection()
    > > Line 89:
    > > Line 90: MessageID = CInt(cmdAddMessage.ExecuteScalar())Line 91:
    > > Line 92: database.CloseConnection()
    > >
    > >
    > > Source File: c:\inetpub\wwwroot\SecurePages\Compose.aspx.vb Line: 90
    > >
    > > Stack Trace:
    > >
    > > [InvalidCastException: Object must implement IConvertible.]
    > > System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
    > > cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
    > > System.Data.SqlClient.SqlCommand.ExecuteScalar()
    > > hpsql.Compose.btnSendMessage_Click(Object sender, ImageClickEventArgs

    > e)
    > > in c:\inetpub\wwwroot\SecurePages\Compose.aspx.vb:90
    > > System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
    > >
    > >

    >

    System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.Ra
    > > isePostBackEvent(String eventArgument)
    > > System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    > > sourceControl, String eventArgument)
    > > System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    > > System.Web.UI.Page.ProcessRequestMain() +1277
    > >
    > >
    > >
    > > Version Information: Microsoft .NET Framework Version:1.1.4322.573;

    > ASP.NET
    > > Version:1.1.4322.573
    > >
    > >
    > >
    > > what in the world is causing this? thanks! i also tried direct casting

    to
    > > Int64 and Int32 and both failed the same way... BigInt should be a 64bit
    > > integer from what ive heard...
    > >
    > >

    >
    >
     
    Brian Henry, Jul 14, 2004
    #3
  4. Brian Henry

    Brian Henry Guest

    doesnt work here... same IConvertable error


    "Telmo Sampaio" <> wrote in message
    news:Ok0F1$...
    > I tested it using a String type to receive the result of your stored
    > procedure and it worked. You may want to try that.
    >
    > Telmo Sampaio
    >
    > "Brian Henry" <> wrote in message
    > news:...
    > > Hi, I am doing the following stored procedure
    > >
    > > CREATE PROCEDURE [dbo].[RSMN_AddMessage]
    > > @sender varchar(50),
    > > @subject varchar(400),
    > > @messagebody text,
    > > @hasAttachments bit,
    > > @sentTime DateTime
    > > AS
    > >
    > >
    > > insert into messages(sendername, subject, messagebody, hasattachments,
    > > senttime)
    > > values (@sender, @subject, @messagebody, @hasAttachments, @sentTime)
    > >
    > > select scope_identity()
    > > GO
    > >
    > > which, the ID field of it (MessageID bigint) is a bigint data type in

    SQL
    > > Server 2000... when I execute this in query anaylzer it works perfectly

    > and
    > > returns a ID number for the identity column MessageID... but when I run

    > this
    > > in VB.NET with this code
    > >
    > > database.OpenConnection()
    > > MessageID = CInt(cmdAddMessage.ExecuteScalar())
    > > database.CloseConnection()
    > >
    > > it comes back with this on my asp.net page as the error...
    > >
    > >
    > > Server Error in '/' Application.
    > >
    > >
    > > Object must implement IConvertible.
    > > Description: An unhandled exception occurred during the execution of the
    > > current web request. Please review the stack trace for more information
    > > about the error and where it originated in the code.
    > >
    > > Exception Details: System.InvalidCastException: Object must implement
    > > IConvertible.
    > >
    > > Source Error:
    > >
    > > Line 88: database.OpenConnection()
    > > Line 89:
    > > Line 90: MessageID = CInt(cmdAddMessage.ExecuteScalar())Line 91:
    > > Line 92: database.CloseConnection()
    > >
    > >
    > > Source File: c:\inetpub\wwwroot\SecurePages\Compose.aspx.vb Line: 90
    > >
    > > Stack Trace:
    > >
    > > [InvalidCastException: Object must implement IConvertible.]
    > > System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
    > > cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
    > > System.Data.SqlClient.SqlCommand.ExecuteScalar()
    > > hpsql.Compose.btnSendMessage_Click(Object sender, ImageClickEventArgs

    > e)
    > > in c:\inetpub\wwwroot\SecurePages\Compose.aspx.vb:90
    > > System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
    > >
    > >

    >

    System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.Ra
    > > isePostBackEvent(String eventArgument)
    > > System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    > > sourceControl, String eventArgument)
    > > System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    > > System.Web.UI.Page.ProcessRequestMain() +1277
    > >
    > >
    > >
    > > Version Information: Microsoft .NET Framework Version:1.1.4322.573;

    > ASP.NET
    > > Version:1.1.4322.573
    > >
    > >
    > >
    > > what in the world is causing this? thanks! i also tried direct casting

    to
    > > Int64 and Int32 and both failed the same way... BigInt should be a 64bit
    > > integer from what ive heard...
    > >
    > >

    >
    >
     
    Brian Henry, Jul 14, 2004
    #4
  5. try the cast using Int64. If I remember correctly, that's what BigInt maps
    back to.

    --

    W.G. Ryan, eMVP

    Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
    Let Microsoft know!
    https://www.windowsembeddedeval.com/community/newsgroups
    "Brian Henry" <> wrote in message
    news:...
    > Hi, I am doing the following stored procedure
    >
    > CREATE PROCEDURE [dbo].[RSMN_AddMessage]
    > @sender varchar(50),
    > @subject varchar(400),
    > @messagebody text,
    > @hasAttachments bit,
    > @sentTime DateTime
    > AS
    >
    >
    > insert into messages(sendername, subject, messagebody, hasattachments,
    > senttime)
    > values (@sender, @subject, @messagebody, @hasAttachments, @sentTime)
    >
    > select scope_identity()
    > GO
    >
    > which, the ID field of it (MessageID bigint) is a bigint data type in SQL
    > Server 2000... when I execute this in query anaylzer it works perfectly

    and
    > returns a ID number for the identity column MessageID... but when I run

    this
    > in VB.NET with this code
    >
    > database.OpenConnection()
    > MessageID = CInt(cmdAddMessage.ExecuteScalar())
    > database.CloseConnection()
    >
    > it comes back with this on my asp.net page as the error...
    >
    >
    > Server Error in '/' Application.
    >
    >
    > Object must implement IConvertible.
    > Description: An unhandled exception occurred during the execution of the
    > current web request. Please review the stack trace for more information
    > about the error and where it originated in the code.
    >
    > Exception Details: System.InvalidCastException: Object must implement
    > IConvertible.
    >
    > Source Error:
    >
    > Line 88: database.OpenConnection()
    > Line 89:
    > Line 90: MessageID = CInt(cmdAddMessage.ExecuteScalar())Line 91:
    > Line 92: database.CloseConnection()
    >
    >
    > Source File: c:\inetpub\wwwroot\SecurePages\Compose.aspx.vb Line: 90
    >
    > Stack Trace:
    >
    > [InvalidCastException: Object must implement IConvertible.]
    > System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
    > cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
    > System.Data.SqlClient.SqlCommand.ExecuteScalar()
    > hpsql.Compose.btnSendMessage_Click(Object sender, ImageClickEventArgs

    e)
    > in c:\inetpub\wwwroot\SecurePages\Compose.aspx.vb:90
    > System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
    >
    >

    System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.Ra
    > isePostBackEvent(String eventArgument)
    > System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    > sourceControl, String eventArgument)
    > System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    > System.Web.UI.Page.ProcessRequestMain() +1277
    >
    >
    >
    > Version Information: Microsoft .NET Framework Version:1.1.4322.573;

    ASP.NET
    > Version:1.1.4322.573
    >
    >
    >
    > what in the world is causing this? thanks! i also tried direct casting to
    > Int64 and Int32 and both failed the same way... BigInt should be a 64bit
    > integer from what ive heard...
    >
    >
     
    William Ryan eMVP, Jul 14, 2004
    #5
  6. Brian Henry

    Brian Henry Guest

    didn't work, same error


    "Telmo Sampaio" <> wrote in message
    news:Ok0F1$...
    > I tested it using a String type to receive the result of your stored
    > procedure and it worked. You may want to try that.
    >
    > Telmo Sampaio
    >
    > "Brian Henry" <> wrote in message
    > news:...
    > > Hi, I am doing the following stored procedure
    > >
    > > CREATE PROCEDURE [dbo].[RSMN_AddMessage]
    > > @sender varchar(50),
    > > @subject varchar(400),
    > > @messagebody text,
    > > @hasAttachments bit,
    > > @sentTime DateTime
    > > AS
    > >
    > >
    > > insert into messages(sendername, subject, messagebody, hasattachments,
    > > senttime)
    > > values (@sender, @subject, @messagebody, @hasAttachments, @sentTime)
    > >
    > > select scope_identity()
    > > GO
    > >
    > > which, the ID field of it (MessageID bigint) is a bigint data type in

    SQL
    > > Server 2000... when I execute this in query anaylzer it works perfectly

    > and
    > > returns a ID number for the identity column MessageID... but when I run

    > this
    > > in VB.NET with this code
    > >
    > > database.OpenConnection()
    > > MessageID = CInt(cmdAddMessage.ExecuteScalar())
    > > database.CloseConnection()
    > >
    > > it comes back with this on my asp.net page as the error...
    > >
    > >
    > > Server Error in '/' Application.
    > >
    > >
    > > Object must implement IConvertible.
    > > Description: An unhandled exception occurred during the execution of the
    > > current web request. Please review the stack trace for more information
    > > about the error and where it originated in the code.
    > >
    > > Exception Details: System.InvalidCastException: Object must implement
    > > IConvertible.
    > >
    > > Source Error:
    > >
    > > Line 88: database.OpenConnection()
    > > Line 89:
    > > Line 90: MessageID = CInt(cmdAddMessage.ExecuteScalar())Line 91:
    > > Line 92: database.CloseConnection()
    > >
    > >
    > > Source File: c:\inetpub\wwwroot\SecurePages\Compose.aspx.vb Line: 90
    > >
    > > Stack Trace:
    > >
    > > [InvalidCastException: Object must implement IConvertible.]
    > > System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
    > > cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
    > > System.Data.SqlClient.SqlCommand.ExecuteScalar()
    > > hpsql.Compose.btnSendMessage_Click(Object sender, ImageClickEventArgs

    > e)
    > > in c:\inetpub\wwwroot\SecurePages\Compose.aspx.vb:90
    > > System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
    > >
    > >

    >

    System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.Ra
    > > isePostBackEvent(String eventArgument)
    > > System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    > > sourceControl, String eventArgument)
    > > System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    > > System.Web.UI.Page.ProcessRequestMain() +1277
    > >
    > >
    > >
    > > Version Information: Microsoft .NET Framework Version:1.1.4322.573;

    > ASP.NET
    > > Version:1.1.4322.573
    > >
    > >
    > >
    > > what in the world is causing this? thanks! i also tried direct casting

    to
    > > Int64 and Int32 and both failed the same way... BigInt should be a 64bit
    > > integer from what ive heard...
    > >
    > >

    >
    >
     
    Brian Henry, Jul 14, 2004
    #6
  7. Try this:

    ///
    sqlCommand1.Parameters["@sender"].Value="1";

    sqlCommand1.Parameters["@subject"].Value="1";

    sqlCommand1.Parameters["@messagebody"].Value="1";

    sqlCommand1.Parameters["@hasAttachments"].Value=0;

    sqlCommand1.Parameters["@sentTime"].Value=Convert.ToDateTime("1/1/2004");

    sqlConnection1.Open();

    try

    {

    decimal a = (decimal)sqlCommand1.ExecuteScalar();

    MessageBox.Show(a.ToString());

    }

    catch (System.Data.SqlClient.SqlException ex)

    {

    foreach (System.Data.SqlClient.SqlError se in ex.Errors)

    MessageBox.Show(se.ToString());

    }

    finally

    {

    sqlConnection1.Close();

    }

    ///



    Telmo

    "Brian Henry" <> wrote in message
    news:...
    > Hi, I am doing the following stored procedure
    >
    > CREATE PROCEDURE [dbo].[RSMN_AddMessage]
    > @sender varchar(50),
    > @subject varchar(400),
    > @messagebody text,
    > @hasAttachments bit,
    > @sentTime DateTime
    > AS
    >
    >
    > insert into messages(sendername, subject, messagebody, hasattachments,
    > senttime)
    > values (@sender, @subject, @messagebody, @hasAttachments, @sentTime)
    >
    > select scope_identity()
    > GO
    >
    > which, the ID field of it (MessageID bigint) is a bigint data type in SQL
    > Server 2000... when I execute this in query anaylzer it works perfectly

    and
    > returns a ID number for the identity column MessageID... but when I run

    this
    > in VB.NET with this code
    >
    > database.OpenConnection()
    > MessageID = CInt(cmdAddMessage.ExecuteScalar())
    > database.CloseConnection()
    >
    > it comes back with this on my asp.net page as the error...
    >
    >
    > Server Error in '/' Application.
    >
    >
    > Object must implement IConvertible.
    > Description: An unhandled exception occurred during the execution of the
    > current web request. Please review the stack trace for more information
    > about the error and where it originated in the code.
    >
    > Exception Details: System.InvalidCastException: Object must implement
    > IConvertible.
    >
    > Source Error:
    >
    > Line 88: database.OpenConnection()
    > Line 89:
    > Line 90: MessageID = CInt(cmdAddMessage.ExecuteScalar())Line 91:
    > Line 92: database.CloseConnection()
    >
    >
    > Source File: c:\inetpub\wwwroot\SecurePages\Compose.aspx.vb Line: 90
    >
    > Stack Trace:
    >
    > [InvalidCastException: Object must implement IConvertible.]
    > System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
    > cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
    > System.Data.SqlClient.SqlCommand.ExecuteScalar()
    > hpsql.Compose.btnSendMessage_Click(Object sender, ImageClickEventArgs

    e)
    > in c:\inetpub\wwwroot\SecurePages\Compose.aspx.vb:90
    > System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
    >
    >

    System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.Ra
    > isePostBackEvent(String eventArgument)
    > System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    > sourceControl, String eventArgument)
    > System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    > System.Web.UI.Page.ProcessRequestMain() +1277
    >
    >
    >
    > Version Information: Microsoft .NET Framework Version:1.1.4322.573;

    ASP.NET
    > Version:1.1.4322.573
    >
    >
    >
    > what in the world is causing this? thanks! i also tried direct casting to
    > Int64 and Int32 and both failed the same way... BigInt should be a 64bit
    > integer from what ive heard...
    >
    >
     
    Telmo Sampaio, Jul 14, 2004
    #7
  8. Brian Henry

    Brian Henry Guest

    found the error, someone was passing the sender object in as a paramater...
    cant believe it was something that stupid... but so well hidden in code



    "Telmo Sampaio" <> wrote in message
    news:...
    > Try this:
    >
    > ///
    > sqlCommand1.Parameters["@sender"].Value="1";
    >
    > sqlCommand1.Parameters["@subject"].Value="1";
    >
    > sqlCommand1.Parameters["@messagebody"].Value="1";
    >
    > sqlCommand1.Parameters["@hasAttachments"].Value=0;
    >
    > sqlCommand1.Parameters["@sentTime"].Value=Convert.ToDateTime("1/1/2004");
    >
    > sqlConnection1.Open();
    >
    > try
    >
    > {
    >
    > decimal a = (decimal)sqlCommand1.ExecuteScalar();
    >
    > MessageBox.Show(a.ToString());
    >
    > }
    >
    > catch (System.Data.SqlClient.SqlException ex)
    >
    > {
    >
    > foreach (System.Data.SqlClient.SqlError se in ex.Errors)
    >
    > MessageBox.Show(se.ToString());
    >
    > }
    >
    > finally
    >
    > {
    >
    > sqlConnection1.Close();
    >
    > }
    >
    > ///
    >
    >
    >
    > Telmo
    >
    > "Brian Henry" <> wrote in message
    > news:...
    > > Hi, I am doing the following stored procedure
    > >
    > > CREATE PROCEDURE [dbo].[RSMN_AddMessage]
    > > @sender varchar(50),
    > > @subject varchar(400),
    > > @messagebody text,
    > > @hasAttachments bit,
    > > @sentTime DateTime
    > > AS
    > >
    > >
    > > insert into messages(sendername, subject, messagebody, hasattachments,
    > > senttime)
    > > values (@sender, @subject, @messagebody, @hasAttachments, @sentTime)
    > >
    > > select scope_identity()
    > > GO
    > >
    > > which, the ID field of it (MessageID bigint) is a bigint data type in

    SQL
    > > Server 2000... when I execute this in query anaylzer it works perfectly

    > and
    > > returns a ID number for the identity column MessageID... but when I run

    > this
    > > in VB.NET with this code
    > >
    > > database.OpenConnection()
    > > MessageID = CInt(cmdAddMessage.ExecuteScalar())
    > > database.CloseConnection()
    > >
    > > it comes back with this on my asp.net page as the error...
    > >
    > >
    > > Server Error in '/' Application.
    > >
    > >
    > > Object must implement IConvertible.
    > > Description: An unhandled exception occurred during the execution of the
    > > current web request. Please review the stack trace for more information
    > > about the error and where it originated in the code.
    > >
    > > Exception Details: System.InvalidCastException: Object must implement
    > > IConvertible.
    > >
    > > Source Error:
    > >
    > > Line 88: database.OpenConnection()
    > > Line 89:
    > > Line 90: MessageID = CInt(cmdAddMessage.ExecuteScalar())Line 91:
    > > Line 92: database.CloseConnection()
    > >
    > >
    > > Source File: c:\inetpub\wwwroot\SecurePages\Compose.aspx.vb Line: 90
    > >
    > > Stack Trace:
    > >
    > > [InvalidCastException: Object must implement IConvertible.]
    > > System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
    > > cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
    > > System.Data.SqlClient.SqlCommand.ExecuteScalar()
    > > hpsql.Compose.btnSendMessage_Click(Object sender, ImageClickEventArgs

    > e)
    > > in c:\inetpub\wwwroot\SecurePages\Compose.aspx.vb:90
    > > System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e)
    > >
    > >

    >

    System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.Ra
    > > isePostBackEvent(String eventArgument)
    > > System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
    > > sourceControl, String eventArgument)
    > > System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    > > System.Web.UI.Page.ProcessRequestMain() +1277
    > >
    > >
    > >
    > > Version Information: Microsoft .NET Framework Version:1.1.4322.573;

    > ASP.NET
    > > Version:1.1.4322.573
    > >
    > >
    > >
    > > what in the world is causing this? thanks! i also tried direct casting

    to
    > > Int64 and Int32 and both failed the same way... BigInt should be a 64bit
    > > integer from what ive heard...
    > >
    > >

    >
    >
     
    Brian Henry, Jul 14, 2004
    #8
    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:
    906
    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:
    501
    Bob Frasca
    Jul 29, 2003
  3. Philip Townsend
    Replies:
    1
    Views:
    558
    Mark Fitzpatrick
    Jun 3, 2004
  4. =?Utf-8?B?VGltOjouLg==?=

    Error: Object must implement IConvertible

    =?Utf-8?B?VGltOjouLg==?=, Dec 14, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,155
    Guest
    Dec 14, 2004
  5. NeoGeoSNK
    Replies:
    25
    Views:
    972
    NeoGeoSNK
    Nov 24, 2006
Loading...

Share This Page