473,666 Members | 2,386 Online
Bytes | Software Development & Data Engineering Community
+ 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.Sql Client.SqlExcep tion: Invalid column
name 'categoryid'.
Line 123: dbComm.ExecuteN onQuery()

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

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.Sql Client
Imports System.Configur ation

Public Class dgrid3
Inherits System.Web.UI.P age

Private strSql As String
Private objConn As SqlConnection

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArg s) 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 =Northwind;Inte grated
Security=SSPI")
Dim objCmd As New SqlCommand(strS ql, objConn)
Dim _reader As SqlDataReader

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

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

Protected Sub FillCategory(By Val sender As System.Object, ByVal e
As System.EventArg s) Handles ddlDate.Selecte dIndexChanged

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

objConn = New
SqlConnection(" server=(local)\ NetSDK;database =Northwind;Inte grated
Security=SSPI")
Dim objCmd As New SqlCommand(strS ql, objConn)
Dim _reader As SqlDataReader
Try
objConn.Open()
_reader = objCmd.ExecuteR eader
With ddlCategory
.DataSource = _reader
.DataValueField = "categoryid "
.DataTextField = "categoryid "
.DataBind()
End With
ddlCategory.Ite ms.Insert(0, "-Select-")
Catch ex As SqlException
Response.Write( ex.ToString)
Finally
_reader.Close()
objConn.Dispose ()
End Try
End Sub

Protected Sub Fillmarket(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles ddlCategory.Sel ectedIndexChang ed
'Clear Titles Textbox
txtMarket.Text = ""
'Fill Titles TextBox
Dim strSql2 As String = "SELECT market FROM Testmarket " & _
"WHERE categoryid='" & ddlCategory.Sel ectedValue() &
"'"
objConn = New
SqlConnection(" server=(local)\ NetSDK;database =Northwind;Inte grated
Security=SSPI")
Dim objCmd As New SqlCommand(strS ql2, objConn)
Dim _reader As SqlDataReader
Try
objConn.Open()
_reader = objCmd.ExecuteR eader(CommandBe havior.SingleRo w)
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(By Val sender As System.Object, ByVal e As
System.EventArg s) Handles Update.Click
objConn = New
SqlConnection(" server=(local)\ netSDK;database =Northwind;Inte grated
Security=SSPI")
Dim strSQL3 As String = "UPDATE Testmarket SET market = " &
txtMarket.Text & "WHERE categoryid='" & ddlCategory.Sel ectedValue() &
"'"

Dim dbComm As New SqlCommand(strS QL3, objConn)
objConn.Open()
dbComm.ExecuteN onQuery()
objConn.Close()
End Sub

End Class
Nov 18 '05 #1
0 2426

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

Similar topics

7
4071
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
2348
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
349
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 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.
16
3485
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 in a hidden field) I wish the user to be able to edit the data in the table, so I have extracted the records into hiddenfield, textareas, dropdown list and checkbox so that they can make changes. I named these elements as arrays and wish to run an...
1
6470
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 (FieldName-Authorised) which has a datatype bit through DataGrid but not sure how to go about it. Any Ideas Guys on this one, your help is greatly appreciated. This is the procedure used to populate the datagrid, The primary key for the table is EntryID which...
1
3203
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 construct the update query so that it picks up when a user checks/unchecks the checkbox and updates the db w/ the matching record ID#. Right now, if a user unchecks a box, the value does not get passed and the DB does not update - set/change it to...
3
2059
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 columns : EmpID, Emp Name, Password, Emp Type. Now when i remove the value EmpID, the gridview does not update. it just reloads when i hit update but no changes are made. On the other hand say i make Emp Type as Read only, when i update .. the...
1
2566
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 able to add/delete/edit. Ive worked out how to add and delete entries but Im stuck with the editing part, everytime when you click the Edit button after checking a box of the record you want to edit (and ofcourse changed the text inside the field) it...
2
2629
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 update the information which is stored in a SQL database. In testing we noticed that the form was updating correctly but the update mechanism was also updating the first record of the table in the sql database every time. No error messages are on...
0
8440
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8355
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8781
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8550
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8638
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4365
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2769
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2006
muto222
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.