Must implement IConvertable?!

  • Thread starter Thread starter Brian Henry
  • Start date Start date
B

Brian Henry

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...
 
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
 
tried it like this

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

still same error



William Ryan eMVP said:
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 said:
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...
 
doesnt work here... same IConvertable error


Telmo Sampaio said:
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 said:
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...
 
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 said:
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...
 
didn't work, same error


Telmo Sampaio said:
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 said:
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...
 
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 said:
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...
 
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 said:
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 said:
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...
 
Back
Top