473,669 Members | 2,523 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Updating field in table

..Net 2003, 1.1, Access database. oledb connection

Hey there, I had my program updating to the database with a dataset,,,
doing things the easy way, binding the dataset to the text box n such,
then having a button to update it, now it has just stopped working. But
everything else works so the connection is still there.

Was wondering if anyone could just tell me the basic code to update a
field in table.

I have a combo box (cbocust) which displays the list of customers in
the table then I have a few txtboxes that display the current
information (this all works fine), all I want is for someone to select
the user from the combo box then to edit the text box's then press a
button and it will update the selected user in the table with the
updated information. Anyone got a quick solution for this? I've tried
looking around, but I'm brand new at this and don't understand most of
the syntax and stuff yet.

Any help would be greatly appreciated. Cheers.

Jun 5 '06 #1
4 1193
Get the PK (CustomerID ??) from the combo box.
Create an update statement in SQL:

' Assumes you have an oledb connection called DBC
Dim sql as string = "UPDATE Customer SET FirstName = '" &
txtFirstName.Te xt
sql &= "' WHERE CustomerID=" & CustomerID.ToSt ring()
Dim com as new oledb.oledbcomm and(sql, dbc)
dbc.Open()
com.ExecuteNonQ uery()
dbc.Close()

This solution doesn't use databindings.
If your dataset/datatable DOES have the correct data in it after you
have made changes in the textbox (verify this in the watch window in
debug mode) then you can just use a dataAdapter to update the dataset.

If this doesn't help, post your code for your save button.

SN
Bonzol wrote:
.Net 2003, 1.1, Access database. oledb connection

Hey there, I had my program updating to the database with a dataset,,,
doing things the easy way, binding the dataset to the text box n such,
then having a button to update it, now it has just stopped working. But
everything else works so the connection is still there.

Was wondering if anyone could just tell me the basic code to update a
field in table.

I have a combo box (cbocust) which displays the list of customers in
the table then I have a few txtboxes that display the current
information (this all works fine), all I want is for someone to select
the user from the combo box then to edit the text box's then press a
button and it will update the selected user in the table with the
updated information. Anyone got a quick solution for this? I've tried
looking around, but I'm brand new at this and don't understand most of
the syntax and stuff yet.

Any help would be greatly appreciated. Cheers.


Jun 5 '06 #2
ok im a bit confused with how this is set out,, ive clearly dont it
wrong

Dim sql As String = "UPDATE Customer SET CustName = '" & txtName.Text
sql &= "' WHERE CustomerID=" & CustomerID.ToSt ring()
Dim com As New OleDb.OleDbComm and(sql, OleDbConnection 1)
OleDbConnection 1.Open()
com.ExecuteNonQ uery()
OleDbConnection 1.Close()

My Dim SQL string is wrong and I cant see where.

Jun 5 '06 #3
ok, ive made a new database, a new form, just very basic to figure this
out

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim First As String = "bob"
Dim sql As String = "UPDATE People SET Last = '" & last.Text
sql & = "' WHERE First=" & First.ToString( )
Dim com As New OleDb.OleDbComm and(sql, OleDbConnection 1)
OleDbConnection 1.Open()
com.ExecuteNonQ uery()
OleDbConnection 1.Close()
' OleDbDataAdapte r1.Update(Custd ata1)
End Sub

just get an error in the SQL string (end of statment expected), can
anyone see it?

Jun 5 '06 #4
Maybe its the way your apostrophe's are ordered?

In sql, any strings need to be surrounded by single quotes.
Eg.

UPDATE People SET Last = 'Smith' WHERE First='John'

I don't think you have quotes around your first name.
If its an integer, it doesn't need quotes around it.

sql & = "' WHERE First='" & First.ToString( ) & "'"

Bonzol wrote:
ok, ive made a new database, a new form, just very basic to figure this
out

Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click
Dim First As String = "bob"
Dim sql As String = "UPDATE People SET Last = '" & last.Text
sql & = "' WHERE First=" & First.ToString( )
Dim com As New OleDb.OleDbComm and(sql, OleDbConnection 1)
OleDbConnection 1.Open()
com.ExecuteNonQ uery()
OleDbConnection 1.Close()
' OleDbDataAdapte r1.Update(Custd ata1)
End Sub

just get an error in the SQL string (end of statment expected), can
anyone see it?


Jun 5 '06 #5

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

Similar topics

11
16166
by: Jason | last post by:
Let's say I have an html form with 20 or 30 fields in it. The form submits the fields via POST to a php page which updates a table in a database with the $_POST vars. Which makes more sense? 1) simply UPDATING the values for all fields in the table, whether or not any particular field has actually changed 2) running a second SELECT statement and comparing the $_POST vars to the returned values, and only UPDATING those that have...
5
2027
by: junglist | last post by:
Hi guys, I've been trying to implement an editable datagrid and i have been succesful up to the point where i can update my datagrid row by row. However what used to happen was that once i updated one row, all of them were updated so i immediatelly figured out that i have to include the id of every entry in the update statement. This is where the problem is raised. My database is an Access database. The table i am updating contains a Date...
4
2370
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has two fields: a primary key and another holding a string. In table B there are three fields: a primary key, a foreign key (which links to the primary key in A) and other field holding a string.
2
3309
by: =?Utf-8?B?VmFuZXNzYQ==?= | last post by:
Hi All! I am with a situation where I am not getting the right updating to the form's fields. The situation is the following one: I have one combobox and one textbox. I am using the CurrentChanged event of the BindingSource of the combobox to update the textbox. When selecting an item in the combobox or when selecting a row in the grid, it is updating the textbox correctly. The problem is when I apply a filter in the grid, and then...
5
3879
by: HSXWillH | last post by:
I have a table entitled Stock_Catalog. Fields include Stock_ID (random autonumber), Brand, Card_Number and Player_Name. Most of the entries have 1 name in the Player_Name field, but some show multiple players and have entry format such as Warren Spahn/Jim O'Toole/etc.... What I currently have is upon closing out the Stock_Catalog entry form, code runs to append the Player_Name to a table titled Player_Hdr where I then add details about the...
0
8466
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
8384
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
8896
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8810
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...
0
8659
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
7410
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5683
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
4208
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1790
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.