| Author |
Topic Search Topic Options
|
Misty
Senior Member
Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
|
Post Options
Thanks(0)
Quote Reply
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
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
Posted: 01 June 2005 at 4:28am |
|
try changing
cmdSql.Parameters.Add( "@Cost", strCost )
to
cmdSql.Parameters.Add( "@Cost", strCost, SqlDbType.Money )
|
 |
Misty
Senior Member
Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
|
Post Options
Thanks(0)
Quote Reply
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 )
|
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
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
|
 |
Misty
Senior Member
Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
|
Post Options
Thanks(0)
Quote Reply
Posted: 01 June 2005 at 9:25pm |
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 )
|
|
 |
Mart
Senior Member
Joined: 30 November 2002
Status: Offline
Points: 2304
|
Post Options
Thanks(0)
Quote Reply
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?
|
 |
Misty
Senior Member
Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
|
Post Options
Thanks(0)
Quote Reply
Posted: 02 June 2005 at 12:27pm |
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.
|
 |
Misty
Senior Member
Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
|
Post Options
Thanks(0)
Quote Reply
Posted: 02 June 2005 at 4:38pm |
I just solved the problem by using cmdSql.Parameters.Add("@Cost", CSng(strCost)).
|
 |