Server Error Understanding

L

Leon Shaw

Please help me understand this Error???

Server Error in '/solo' 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 509: Me.cmdAddMember.Parameters(30).Value =
Me.txtCurrentDate.Text
Line 510: Me.cmdAddMember.Connection.Open()
Line 511: Me.cmdAddMember.ExecuteNonQuery()
Line 512: Me.cmdAddMember.Connection.Close()
Line 513: Me.txtMemberId.Visible = True

Source File: c:\inetpub\wwwroot\solo\reg\index.aspx.vb Line: 511

Stack Trace:

[InvalidCastException: Object must implement IConvertible.]
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +723
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +196
solo.index.btSubmit_Click(Object sender, EventArgs e) in
c:\inetpub\wwwroot\solo\reg\index.aspx.vb:511
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
stBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
 
J

John Saunders

What is the data type for parameter 30? datetime? In that case, try:

cmdAddMember.Parameters(30).Value = DateTime.Parse(txtCurrentDate.Text)


--
John Saunders
Internet Engineer
(e-mail address removed)

BTW, notice that you don't have to say "Me.".
 
J

John Saunders

Yes. The problem is that you're supplying strings to your smalldatetime
parameters. You need to use cmdAddMember.Parameter(n).Value =
DateTime.Parse(whatever.Text).

Once you get that working, I'd also recommend that you stop using numeric
indexes for the parameters. What happens to your code if the order of the
parameters changes? Try cmdAddMember.Parameter("@RenewalDate").Value
instead.

--
John Saunders
Internet Engineer
(e-mail address removed)

P.S. Don't you get tired of typing "Me." all the time?


Leon Shaw said:
(Do You See A Problem!) This is the Store Proceduce I'm using.

REATE PROCEDURE [Add_Member]
(@Username [varchar](20),
@Password [varchar](16),
@SecretQuestion [varchar](50),
@SecretAnswer [varchar](64),
@FirstName [varchar](64),
@LastName [varchar](64),
@BirthMonth [varchar](10),
@BirthDay [tinyint],
@BirthYear [smallint],
@Gender [varchar](6),
@SchoolState [varchar](50),
@SchoolName [varchar](200),
@Classification [varchar](50),
@Major [varchar](120),
@CreditCardName [varchar](120),
@CreditCardType [varchar](20),
@CreditCardNumber [varchar](16),
@CreditCardExpMonth [varchar](10),
@CreditCardExpYear [smallint],
@BillingAddress1 [varchar](200),
@BillingAddress2 [varchar](200),
@BillingCity [varchar](200),
@BillingState [varchar](50),
@BillingPostalCode [varchar](10),
@EmailAddress [varchar](64),
@PhoneAreaCode [char](3),
@PhoneNumber [varchar](8),
@ActivationDate [smalldatetime],
@RenewalDate [smalldatetime],
@LastUpdate [smalldatetime])

AS INSERT INTO [Stunation].[dbo].[TAB_Member]
( [Username],
[Password],
[SecretQuestion],
[SecretAnswer],
[FirstName],
[LastName],
[BirthMonth],
[BirthDay],
[BirthYear],
[Gender],
[SchoolState],
[SchoolName],
[Classification],
[Major],
[CreditCardName],
[CreditCardType],
[CreditCardNumber],
[CreditCardExpMonth],
[CreditCardExpYear],
[BillingAddress1],
[BillingAddress2],
[BillingCity],
[BillingState],
[BillingPostalCode],
[EmailAddress],
[PhoneAreaCode],
[PhoneNumber],
[ActivationDate],
[RenewalDate],
[LastUpdate])

VALUES
( @Username,
@Password,
@SecretQuestion,
@SecretAnswer,
@FirstName,
@LastName,
@BirthMonth,
@BirthDay,
@BirthYear,
@Gender,
@SchoolState,
@SchoolName,
@Classification,
@Major,
@CreditCardName,
@CreditCardType,
@CreditCardNumber,
@CreditCardExpMonth,
@CreditCardExpYear,
@BillingAddress1,
@BillingAddress2,
@BillingCity,
@BillingState,
@BillingPostalCode,
@EmailAddress,
@PhoneAreaCode,
@PhoneNumber,
@ActivationDate,
@RenewalDate,
@LastUpdate)

SELECT MemberID = @@IDENTITY
GO
This is the code inside of vs.net
If Me.IsValid = True Then

Me.txtMemberId.Text = Me.cmdAddMember.Parameters(0).Value

Me.cmdAddMember.Parameters(1).Value = Me.txtUsername.Text

Me.cmdAddMember.Parameters(2).Value = Me.txtPassword.Text

Me.cmdAddMember.Parameters(3).Value = Me.ddlSecretQuestion.SelectedItem

Me.cmdAddMember.Parameters(4).Value = Me.txtSecretAnswer.Text

Me.cmdAddMember.Parameters(5).Value = Me.txtFirstName.Text

Me.cmdAddMember.Parameters(6).Value = Me.txtLastName.Text

Me.cmdAddMember.Parameters(7).Value = Me.ddlBirthMonth.SelectedItem

Me.cmdAddMember.Parameters(8).Value = Me.ddlBirthDay.SelectedItem

Me.cmdAddMember.Parameters(9).Value = Me.txtBirthYear.Text

Me.cmdAddMember.Parameters(10).Value = Me.rbtGender.SelectedItem

Me.cmdAddMember.Parameters(11).Value = Me.ddlSchoolState.SelectedItem

Me.cmdAddMember.Parameters(12).Value = Me.ddlSchoolName.SelectedItem

Me.cmdAddMember.Parameters(13).Value = Me.ddlClassification.SelectedItem

Me.cmdAddMember.Parameters(14).Value = Me.ddlSchoolMajor.SelectedItem

Me.cmdAddMember.Parameters(15).Value = Me.txtCreditCardName.Text

Me.cmdAddMember.Parameters(16).Value = Me.ddlCreditCardType.SelectedItem

Me.cmdAddMember.Parameters(17).Value = Me.txtCreditCardNumber.Text

Me.cmdAddMember.Parameters(18).Value = Me.ddlExpMonth.SelectedItem

Me.cmdAddMember.Parameters(19).Value = Me.ddlExpYear.SelectedItem

Me.cmdAddMember.Parameters(20).Value = Me.txtBillingAddress1.Text

Me.cmdAddMember.Parameters(21).Value = Me.txtBillingAddress2.Text

Me.cmdAddMember.Parameters(22).Value = Me.txtBillingCity.Text

Me.cmdAddMember.Parameters(23).Value = Me.ddlBillingState.SelectedItem

Me.cmdAddMember.Parameters(24).Value = Me.txtBillingZipCode.Text

Me.cmdAddMember.Parameters(25).Value = Me.txtEmail.Text

Me.cmdAddMember.Parameters(26).Value = Me.txtPhonerAreaCode.Text

Me.cmdAddMember.Parameters(27).Value = Me.txtPhone.Text

Me.cmdAddMember.Parameters(28).Value = Me.txtCurrentDate.Text

Me.cmdAddMember.Parameters(29).Value = (Me.txtFutureDate.Text)

Me.cmdAddMember.Parameters(30).Value = (Me.txtCurrentDate.Text)

Me.cmdAddMember.Connection.Open()

Me.cmdAddMember.ExecuteNonQuery()

Me.cmdAddMember.Connection.Close()

Me.txtMemberId.Visible = True

End If

John Saunders said:
What is the data type for parameter 30? datetime? In that case, try:

cmdAddMember.Parameters(30).Value = DateTime.Parse(txtCurrentDate.Text)


--
John Saunders
Internet Engineer
(e-mail address removed)

BTW, notice that you don't have to say "Me.".

Leon Shaw said:
Please help me understand this Error???

Server Error in '/solo' 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 509: Me.cmdAddMember.Parameters(30).Value =
Me.txtCurrentDate.Text
Line 510: Me.cmdAddMember.Connection.Open()
Line 511: Me.cmdAddMember.ExecuteNonQuery()
Line 512: Me.cmdAddMember.Connection.Close()
Line 513: Me.txtMemberId.Visible = True

Source File: c:\inetpub\wwwroot\solo\reg\index.aspx.vb Line: 511

Stack Trace:

[InvalidCastException: Object must implement IConvertible.]
System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior
cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +723
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +196
solo.index.btSubmit_Click(Object sender, EventArgs e) in
c:\inetpub\wwwroot\solo\reg\index.aspx.vb:511
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top