473,387 Members | 1,592 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,387 software developers and data experts.

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 1184
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.Text
sql &= "' WHERE CustomerID=" & CustomerID.ToString()
Dim com as new oledb.oledbcommand(sql, dbc)
dbc.Open()
com.ExecuteNonQuery()
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.ToString()
Dim com As New OleDb.OleDbCommand(sql, OleDbConnection1)
OleDbConnection1.Open()
com.ExecuteNonQuery()
OleDbConnection1.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(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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.OleDbCommand(sql, OleDbConnection1)
OleDbConnection1.Open()
com.ExecuteNonQuery()
OleDbConnection1.Close()
' OleDbDataAdapter1.Update(Custdata1)
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(ByVal sender As System.Object, ByVal e As
System.EventArgs) 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.OleDbCommand(sql, OleDbConnection1)
OleDbConnection1.Open()
com.ExecuteNonQuery()
OleDbConnection1.Close()
' OleDbDataAdapter1.Update(Custdata1)
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
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? ...
5
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...
4
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...
2
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...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.