473,320 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Update problem while editing text field + populate checkbox value from table

My code as an txt attachment.

I have 2 drop down list boxes that on selection populate text boxes
from my database table. I am able to display the correct values in
these text boxes.
I have 2 questions:

1) I would like the user update these text fields that get populated
with data from the database. For some reason I get the error when I
change the textbox value.
Exception Details: System.Data.SqlClient.SqlException: Invalid column
name 'categoryid'.
Line 123: dbComm.ExecuteNonQuery()

My update query is:
Dim strSQL3 As String = "UPDATE Testmarket SET market = " &
txtMarket.Text & "WHERE categoryid='" & ddlCategory.SelectedValue() &
"'"

What I am doing wrong? categoryid is my primary key.
2) Also, I have checkboxes in the same page that have to be populated
if the column valus is 'Yes'? Do you have an idea of how to do that.

Code:
-------------------------------------------------------------------------------
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration

Public Class dgrid3
Inherits System.Web.UI.Page

Private strSql As String
Private objConn As SqlConnection

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page her

If Not IsPostBack Then
'Fill Date DropDown
strSql = "SELECT categoryid, date FROM Testmarket ORDER BY
categoryid"
objConn = New
SqlConnection("server=(local)\NetSDK;database=Nort hwind;Integrated
Security=SSPI")
Dim objCmd As New SqlCommand(strSql, objConn)
Dim _reader As SqlDataReader

Try
objConn.Open()
_reader = objCmd.ExecuteReader
With ddlDate
.DataSource = _reader
.DataValueField = "categoryid"
.DataTextField = "date"
.DataBind()
End With

ddlDate.Items.Insert(0, "-Select-")
Catch ex As SqlException
Response.Write(ex.ToString)
Finally
_reader.Close()
objConn.Dispose()
End Try
End If
End Sub

Protected Sub FillCategory(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles ddlDate.SelectedIndexChanged

'Fill Category DropDown
strSql = "SELECT categoryid FROM Testmarket " & _
"WHERE categoryid='" & ddlDate.SelectedValue() & "'"
& _
" ORDER BY categoryid"

objConn = New
SqlConnection("server=(local)\NetSDK;database=Nort hwind;Integrated
Security=SSPI")
Dim objCmd As New SqlCommand(strSql, objConn)
Dim _reader As SqlDataReader
Try
objConn.Open()
_reader = objCmd.ExecuteReader
With ddlCategory
.DataSource = _reader
.DataValueField = "categoryid"
.DataTextField = "categoryid"
.DataBind()
End With
ddlCategory.Items.Insert(0, "-Select-")
Catch ex As SqlException
Response.Write(ex.ToString)
Finally
_reader.Close()
objConn.Dispose()
End Try
End Sub

Protected Sub Fillmarket(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ddlCategory.SelectedIndexChanged
'Clear Titles Textbox
txtMarket.Text = ""
'Fill Titles TextBox
Dim strSql2 As String = "SELECT market FROM Testmarket " & _
"WHERE categoryid='" & ddlCategory.SelectedValue() &
"'"
objConn = New
SqlConnection("server=(local)\NetSDK;database=Nort hwind;Integrated
Security=SSPI")
Dim objCmd As New SqlCommand(strSql2, objConn)
Dim _reader As SqlDataReader
Try
objConn.Open()
_reader = objCmd.ExecuteReader(CommandBehavior.SingleRow)
If _reader.Read Then
txtMarket.Text = _reader("market")
End If
Catch ex As SqlException
Response.Write(ex.ToString)
Finally
_reader.Close()
objConn.Dispose()
End Try
End Sub

Private Sub Update_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Update.Click
objConn = New
SqlConnection("server=(local)\netSDK;database=Nort hwind;Integrated
Security=SSPI")
Dim strSQL3 As String = "UPDATE Testmarket SET market = " &
txtMarket.Text & "WHERE categoryid='" & ddlCategory.SelectedValue() &
"'"

Dim dbComm As New SqlCommand(strSQL3, objConn)
objConn.Open()
dbComm.ExecuteNonQuery()
objConn.Close()
End Sub

End Class
Nov 18 '05 #1
0 2403

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Drew | last post by:
I have a db table like the following, UID, int auto-increment RegNo Person Relation YearsKnown Now here is some sample data from this table,
5
by: A.Dagostino | last post by:
hi i need to update an SQL Table when user select or unselect a checkbox control. How Can i do? Thanks Alex
0
by: Nithin | last post by:
My code as an txt attachment. I have 2 drop down list boxes that on selection populate text boxes from my database table. I am able to display the correct values in these text boxes. I have 2...
16
by: Ian Davies | last post by:
Hello Needing help with a suitable solution. I have extracted records into a table under three columns 'category', 'comment' and share (the category column also holds the index no of the record...
1
by: Sharon | last post by:
Hello All, Is it possible to update Sql Table through DataGrid. I have a DataGrid which is being populated through a stored procedure, all i wanted to do is to update one field...
1
by: hmlarson | last post by:
I have a form/table with checkboxes that I would like the user to check / uncheck if they want a certain record to display in a gallery on a website. I'm having problems figuring out how to...
3
by: dhaneshrs | last post by:
I have a gridview i managed to update using the edit option in the smartmenu. The problem comes when i delete a value or make a value read only. Say i have a table Employee with the following...
1
by: mac89 | last post by:
Hi, I was wondering if anyone could help me with this problem. Here is the case, I have a News database which you are able to view here: http://lotrtw.com/news/index_.php And users will be...
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.