Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Converting a Money Value to Update a DB
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Converting a Money Value to Update a DB

 Post Reply Post Reply
Author
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Topic: Converting a Money Value to Update a DB
    Posted: 01 June 2005 at 2:05am
I have an editable datagrid. I am getting the following error message every time I try to update the datagrid: Exception Details: System.Data.SqlClient.SqlException: Disallowed implicit conversion from data type nvarchar to data type money, table '.dbo.WebHosting', column 'Cost'. Use the CONVERT function to run this query.

Source Error:

Line 73:   cmdSql.Parameters.Add( "@WebHostingID", intWebHostingID )
Line 74:   conHosting.Open()
Line 75:   cmdSql.ExecuteNonQuery()


I need help with converting the datatype. Cost is a money datatype.

Here's the code that is causing the problem:

Dim txtCost As TextBox

Dim strCost As String

 

  intWebHostingID = dtrWebHosting.DataKeys( e.Item.ItemIndex )

  txtPlanName = e.Item.Cells( 1 ).Controls( 0 )

  txtDiskspace = e.Item.Cells( 2 ).Controls( 0 )

  txtCost = e.Item.Cells( 3 ).Controls( 0 )

  strPlanName = txtPlanName.Text

  strDiskspace = txtDiskspace.Text

  strCost = txtCost.Text

  strSql = "Update WebHosting Set PlanName=@PlanName, Diskspace=@Diskspace, Cost=@Cost Where WebHostingID=@WebHostingID"

  cmdSql = New SqlCommand( strSql, conHosting )

  cmdSql.Parameters.Add( "@PlanName", strPlanName )

  cmdSql.Parameters.Add( "@Diskspace", strDiskspace )

  cmdSql.Parameters.Add( "@Cost", strCost )

  cmdSql.Parameters.Add( "@WebHostingID", intWebHostingID )

  conHosting.Open()

  cmdSql.ExecuteNonQuery()

Here's my code for the boundcolumn:

  <asp:BoundColumn
    HeaderText="Cost"
    DataField="Cost"
    DataFormatString="{0:C}"/>



Edited by Misty - 01 June 2005 at 9:26pm
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 01 June 2005 at 4:28am
try changing

cmdSql.Parameters.Add( "@Cost", strCost )

to

cmdSql.Parameters.Add( "@Cost", strCost, SqlDbType.Money )
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 01 June 2005 at 4:31pm
Unfortunately, it didn't work. Does anyone have any ideas on how to solve this?
I am getting the following error message now: Compiler Error Message: BC30451: Name 'SqlDbType' is not declared.

Source Error:

 
Line 78:   cmdSql.Parameters.Add( "@Cost", strCost, SqlDbType.Money )
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 01 June 2005 at 4:41pm
Have you imported System.Data?

put

<%@ Import Namespace="System.Data" %>

at the top, you may have only imported System.Data.SqlClient
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 01 June 2005 at 9:25pm
Originally posted by Mart Mart wrote:

Have you imported System.Data?

put

<%@ Import Namespace="System.Data" %>

at the top, you may have only imported System.Data.SqlClient
 
Thank you for reminding me about System.Data! I added it. I'm getting closer to fix the problem. I am still getting the following error message when I try to update the record: Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: @Cost: Invalid SqlDbType enumeration value: 45.

Source Error:

Line 77:   'objData.AddParam(oParam)
Line 78:  
Line 79:   cmdSql.Parameters.Add( "@Cost", strCost, SqlDbType.Money )
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 02 June 2005 at 4:15am
Does your stored procedure/query have a parameter called cost? and have you passed on all other relevant parameters? Does you query contain an error?
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 02 June 2005 at 12:27pm
Originally posted by Mart Mart wrote:

Does your stored procedure/query have a parameter called cost? and have you passed on all other relevant parameters? Does you query contain an error?
 
Yes, there's a parameter called cost. It is also the name of the database field in myh database. When I removed this particular parameter for adding cost, I have no problem with updating the database. I know that the problem is with the cost. I thought that the line of code that you gave me would work. I'm not sure what's wrong.
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Posted: 02 June 2005 at 4:38pm
I just solved the problem by using cmdSql.Parameters.Add("@Cost", CSng(strCost)).
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.