Solved

Problems updating a datarow in sql

Posted on 2008-10-22
8
239 Views
Last Modified: 2012-05-05
I am attempting to update a datarow in a sql database with a selected item in a ddl.  I am using the following code:

 Dim connectionstring As String = ("my connection")
        Dim query As String = ("Update properties Set available='@available' where ID='@ID'")
        Dim conn As New SqlConnection(my connection)
        Dim cmd As New SqlCommand(query, conn)
        cmd.Parameters.AddWithValue("@available", DropDownList4.SelectedItem)
        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
Basically, I want the person to be able to update that particular record.  When I run this application, this is the error I am getting:

System.ArgumentException: No mapping exists from object type System.Web.UI.WebControls.ListItem to a known managed provider native type.
0
Comment
Question by:smitty68521
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 22783419
try:

Dim query As String = ("Update properties Set available=@available where ID=@ID")

instead?

also, you need provide 2 parameters for the command object.
0
 
LVL 1

Author Comment

by:smitty68521
ID: 22783456
I have tried that and I still get the same error. I see what you are saying as far as adding two parameters for the command object. However, I am not sure how to set the command parameter for the ID when it is simply a querystring I use from a previous page that dispays the data in the gridview.

I appreciate your help so far.
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 22783632
try:

        Dim ID As String = ""
        If String.IsNullOrEmpty(Request.QueryString("ID")) = False Then
            ID = Request.QueryString("ID").ToString()
        Else
             'Or redirect or terminate process
        End If

'...

Dim connectionstring As String = ("my connection")
        Dim query As String = ("Update properties Set available=@available where ID=@ID")
        Dim conn As New SqlConnection(my connection)
        Dim cmd As New SqlCommand(query, conn)

        cmd.Parameters.AddWithValue("@available", DropDownList4.SelectedItem)
        cmd.Parameters.AddWithValue("@ID", ID)

        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
0
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
LVL 1

Author Comment

by:smitty68521
ID: 22783742
This didn't work either. It doesn't give any errors this time but it also doesn't update the database. I will keep researching. I tried a request.querystring earlier but it didn't work either. Thanks for your help so far.
0
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 22783767
it works for me, perhaps you can post a more complete scripts here?
0
 
LVL 1

Author Comment

by:smitty68521
ID: 22783829
More complete? What I had in my first post was it. This is what is causing the error. It stops at "execute nonquery" I don't know what more I could provide you with. I am not sure what is going on with this. I have had projects similar to this and got them to work just fine. I appreciate your help so far though.
0
 
LVL 52

Accepted Solution

by:
Ryan Chong earned 500 total points
ID: 22783950
try change:

DropDownList4.SelectedItem

to:

DropDownList4.SelectedItem.Value

?
0
 
LVL 1

Author Closing Comment

by:smitty68521
ID: 31509063
It worked! Thanks for your help. Great Expert.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question