Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'Decimal' cannot be converted to 'System.Web.UI.WebCont..

Status
Not open for further replies.

gtjr92

Programmer
May 26, 2004
96
I keep getting these errors I have a sub that looks at my gridview and then is supposed to update my database with the parameters below but I get these errors below...
Value of type 'Decimal' cannot be converted to 'System.Web.UI.WebControls.Parameter'.
for this line
Code:
"dsoTithe.UpdateParameters.Item("@Titheparam") = CDec("@Titheup")"
If I try iy this way
Code:
dsoTithe.UpdateParameters.Item(CInt("@TRidparam") = CInt("@id"))
Then I get "Property access must assign to the property or use its value."

I am using asp.net 2.0
HEre is the rest of my code for this
Code:
 Sub Updatedb(ByVal sender As Object, ByVal e As EventArgs)
        Dim dgi As GridViewRow
        For Each dgi In GridView1.Rows
            ' Read in the Primary Key Field
            Dim id As Int32 = (GridView1.DataKeys(dgi.RowIndex).Value.ToString())
            Dim Titheup As Decimal = CType(dgi.FindControl("TxtTithe"), TextBox).Text
            dsoTithe.UpdateParameters.Item("@Titheparam") = CDec("@Titheup")
            dsoTithe.UpdateParameters.Item(CInt("@TRidparam") = CInt("@id"))
            dsoTithe.UpdateParameters.Clear()
            dsoTithe.Update()
        Next

    End Sub
Code:
<asp:AccessDataSource ID="dsoTithe" runat="server"   DataFile="~/App_Data/tithe/GBCTITHE.MDB"
            SelectCommand="SELECT [Weeks_Date], [People_ID], [Name], [Tithe], [Education], [Missions], [Special], [Gift_Item], [Gift_Value], [WkID], [TRID] FROM [TblCombine] WHERE ([WkID] = ?)"
            UpdateCommand="UPDATE [Tithe] SET [Tithe]=? Where [trid]=?">
          <UpdateParameters>
     <asp:Parameter Name="Titheparam" Type="Decimal"  />
          <asp:Parameter Name="Tridparam" Type="Int32"  />
                  </UpdateParameters>
            <SelectParameters>
                <asp:ControlParameter ControlID="lbxWeeks" DefaultValue="1" Name="WkID" PropertyName="SelectedValue"
                    Type="Double" />
            </SelectParameters>
            
           </asp:AccessDataSource>
 
By the looks of it, your Titheparam parameter already has a decimal type assigned to it so you would just have to set it the the Titheup variable that is already declared. e.g.
Code:
dsoTithe.UpdateParameters.Item("@Titheparam") = Titheup
I always set parameter's up in code and use a Stored Procedure though.

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
I tried that and I still get the same thing
Value of type 'Decimal' cannot be converted to 'System.Web.UI.WebControls.Parameter'
 
It's telling you you are trying to asign the decimal CDec("@Titheup") object to the parameter object rather than assign it to the value property of the parameter object I believe. Basically your code is trying to set the parameter object to a decimal object which can't be done.

Rhys

""Vampireware /n/, a project, capable of sucking the lifeblood out of anyone unfortunate enough to be assigned to it, which never actually sees the light of day, but nonetheless refuses to die."

My Home
 
Any idea how I can correct this?
I have tried this several different ways
If I do this
Code:
dsoTithe.Update("@TRidparam") = id
"Public Function Update() As Integer' has no parameters and its return type cannot be indexed"
If I do this
Code:
dsoTithe.UpdateParameters.Item(CInt("@TRidparam") = CInt("@id"))
Property access must assign to the property or use its value.
If I don't try to set it to a decimal etc I get
Property access must assign to the property or use its value.
Thanks for the help this is frustrating me!
 
Does the 'dsoTithe.UpdateParameters.Item(CInt("@TRidparam")' object have a Value property?

i.e.,
Code:
dsoTithe.UpdateParameters.Item("@Titheparam").Value = CDec("@Titheup")



Rhys

""Vampireware /n/, a project, capable of sucking the lifeblood out of anyone unfortunate enough to be assigned to it, which never actually sees the light of day, but nonetheless refuses to die."

My Home
 
No it does not have that property it only has default value property
Code:
dsoTithe.UpdateParameters.Item("@Titheparam").Equals(Titheup)
When I am debugging my code I can see that the for each is running properly I can see the value of my Dim Id.. and the dim titheup. I just have to figure out how to get that value to my updatecommand...
Here is the error I get for the code above. Even though I know the titheup and id are not null
Object reference not set to an instance of an object

System.NullReferenceException was unhandled by user code
Message="Object reference not set to an instance of an object."
Source="App_Web_jg0pw-xy"
StackTrace:
at _Default.Updatedb(Object sender, EventArgs e) in C:\gbcweb505\Default.aspx.vb:line 82

at System.Web.UI.WebControls.Button.OnClick(EventArgs e)

at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)

at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)

at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)

at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)

at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
 
Finally I got it here is what I did

thanks for the help
Code:
FINALLY!!! Here is what I did also I did not need the updateparam defined in the datasource since I do that in the VB

Sub Updatedb(ByVal sender As Object, ByVal e As EventArgs)

Dim dgi As GridViewRow

For Each dgi In GridView1.Rows

' Read in the Primary Key Field

Dim id As Int32

id = (GridView1.DataKeys(dgi.RowIndex).Value.ToString())

Dim Titheup As Decimal

Titheup = CType(dgi.FindControl("TxtTithe"), TextBox).Text



dsoTithe.UpdateParameters.Add("@Titheparam", Titheup)

dsoTithe.UpdateParameters.Add("@TRidparam", id)

'Response.Write(dsoTithe.UpdateCommand)

'Response.Write(Titheup) ', dsoTithe.UpdateParameters, dsoTithe.Update

'Response.End()

dsoTithe.Update()

dsoTithe.UpdateParameters.Clear()

Next

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top