?
Solved

Problems updating a datarow in sql

Posted on 2008-10-22
8
Medium Priority
?
241 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 53

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 53

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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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 53

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 53

Accepted Solution

by:
Ryan Chong earned 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

762 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