473,472 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2407

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: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.