473,503 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Add "a new record for a table" problem

HS1
Hello

I have Win application used to add records into a table (called Clients) in
an Access database. I use a DataGrid1 to present records in this table and
use some TextBox(es) to display the details of a selected record.

DataGrid1.DataSource = ds 'ds is a datasource

da1.Fill(ds) 'da1 is a OleDbDataAdapter

I "Set" the content of each TextBox in the Design Properties (at DataBinding
cell) window as the following

TextBox1.setText= ds - Clients.ClientName 'set text of the TextBox1

TextBox2.setText = ds - Clients.ClientAddress

Everything works well. In the textbox1 and textbox2, I can view details of
each record in the DataGrid1

To add record, I create a button Add. When I click this button, a new record
(empty) is added at the end of the DataGrid1. Also, the TexBox1 and TexBox2
are empty. I have this code for Add button event

-----------

Me.BindingContext(ds, "Clients").AddNew()

----------

Then I have another button "Save" to save the new record into database. I
have the code for Save button event

-----------

Dim newClient As DataRow = ds.Tables("Clients").NewRow

newClient("ClientName") = TextBox1.Text

newClient("ClientAddress") = TextBox2.Text

da1.Update(ds, "Clients")

MessageBox.Show(" One record is inserted ")

------------

When I did as above, I can see some records that are added into the
DataGrid1. However only the first record is "really" saved in the database.
That means, after I close the application and open it again, I only see the
first record displayed in the DataGrid1.

Could you please help

Thank you very much

SH1
Nov 21 '05 #1
5 1465
HS,

One of the most classic problems in these dotnet newsgroups. It is strange
you did not get an earlier answer.

When you have added information to the texboxes it is not pushed in the
datatable.
That happens with a rowchange or with forcing that by "standard sample"

BindingContext(ds.Tables(0)).EndCurrentEdit()

I hope this helps?

Cor

"HS1" <so*@slingshot.co.nz>
Hello

I have Win application used to add records into a table (called Clients)
in
an Access database. I use a DataGrid1 to present records in this table and
use some TextBox(es) to display the details of a selected record.

DataGrid1.DataSource = ds 'ds is a datasource

da1.Fill(ds) 'da1 is a
OleDbDataAdapter

I "Set" the content of each TextBox in the Design Properties (at
DataBinding
cell) window as the following

TextBox1.setText= ds - Clients.ClientName 'set text of the
TextBox1

TextBox2.setText = ds - Clients.ClientAddress

Everything works well. In the textbox1 and textbox2, I can view details of
each record in the DataGrid1

To add record, I create a button Add. When I click this button, a new
record
(empty) is added at the end of the DataGrid1. Also, the TexBox1 and
TexBox2
are empty. I have this code for Add button event

-----------

Me.BindingContext(ds, "Clients").AddNew()

----------

Then I have another button "Save" to save the new record into database. I
have the code for Save button event

-----------

Dim newClient As DataRow = ds.Tables("Clients").NewRow

newClient("ClientName") = TextBox1.Text

newClient("ClientAddress") = TextBox2.Text

da1.Update(ds, "Clients")

MessageBox.Show(" One record is inserted ")

------------

When I did as above, I can see some records that are added into the
DataGrid1. However only the first record is "really" saved in the
database.
That means, after I close the application and open it again, I only see
the
first record displayed in the DataGrid1.

Could you please help

Thank you very much

SH1

Nov 21 '05 #2
Thank you for your help (many times before)

When I did as your suggestion:

When I click Add button: the textboxes are empty and there is a new,
empty record in the DataGrid1.

After I enter values in the textboxes and click Save, there two similar
records are presented in the DataGrid1.

I click "Add" again, there is new and empty record in the DataGrid1.
when I click Save, again, there are two more similar records are added
in the DataGrid1.

When I close the application, and run the application again, there are 3
records are saved. The firts two are of the first "Save" and the third
is of the second "Save"

I do not know why. Here is my code:

-------------------
Button Add
----------------

Me.BindingContext(ds, "ClienMe.BindingContext(ds, "Clients").AddNew()
'for obtaining a new and empty row in the DataGrid1

-------
Button SAVE
--------

Dim newClient As DataRow = ds.Tables("Clients").NewRow
newClient("C_FName") = TextBox1.Text
newClient("C_LName") = TextBox2.Text
ds.Tables(0).Rows.Add(newClient)
da1.Update(ds, "Clients")
Me.BindingContext(ds, "Clients").EndCurrentEdit()

------------------------

My application is very simple but I do not know what happen

Please help
Thank you
SH1
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3
Thank you for your help (many times before)

When I did as your suggestion:

When I click Add button: the textboxes are empty and there is a new,
empty record in the DataGrid1.

After I enter values in the textboxes and click Save, there two similar
records are presented in the DataGrid1.

I click "Add" again, there is new and empty record in the DataGrid1.
when I click Save, again, there are two more similar records are added
in the DataGrid1.

When I close the application, and run the application again, there are 3
records are saved. The firts two are of the first "Save" and the third
is of the second "Save"

I do not know why. Here is my code:

-------------------
Button Add
----------------

Me.BindingContext(ds, "ClienMe.BindingContext(ds, "Clients").AddNew()
'for obtaining a new and empty row in the DataGrid1

-------
Button SAVE
--------

Dim newClient As DataRow = ds.Tables("Clients").NewRow
newClient("C_FName") = TextBox1.Text
newClient("C_LName") = TextBox2.Text
ds.Tables(0).Rows.Add(newClient)
da1.Update(ds, "Clients")
Me.BindingContext(ds, "Clients").EndCurrentEdit()

------------------------

My application is very simple but I do not know what happen

Please help
Thank you
SH1
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #4
John,
' Dim newClient As DataRow = ds.Tables("Clients").NewRow
'newClient("C_FName") = TextBox1.Text
'newClient("C_LName") = TextBox2.Text
'ds.Tables(0).Rows.Add(newClient)

The ones above should not be needed
Me.BindingContext(ds, "Clients").EndCurrentEdit()
da1.Update(ds, "Clients")

I hope this helps?

Cor
Nov 21 '05 #5
John,
' Dim newClient As DataRow = ds.Tables("Clients").NewRow
'newClient("C_FName") = TextBox1.Text
'newClient("C_LName") = TextBox2.Text
'ds.Tables(0).Rows.Add(newClient)

The ones above should not be needed
Me.BindingContext(ds, "Clients").EndCurrentEdit()
da1.Update(ds, "Clients")

I hope this helps?

Cor
Nov 21 '05 #6

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

Similar topics

7
1832
by: CAH | last post by:
I once wrote on usenet and got a very good answer . This one JN wrote: > >| Should one place all the text in one big table, or is i better to place > >| it in several tabels. Should one make 4...
7
1855
by: David Findlay | last post by:
I'm trying to do a table for laying out a links page in CSS. See http://qldstorms.com/links.php. My stylesheet is at http://qldstorms.com/styles/screen.css. My problem is that if the link name in...
0
1751
by: William Wisnieski | last post by:
Hello Everyone: I'm having a very strange problem occurring with my Access 2000 database. I call it the "mystery record." Here's the story: I have a query by form that returns a record set...
8
9211
by: Bri | last post by:
Greetings, I'm having a very strange problem in an AC97 MDB with ODBC Linked tables to SQL Server 7. The table has an Identity field and a Timestamp field. The problem is that when a new record...
3
2201
by: domcatanzarite | last post by:
How would one create a button that on click advances the form to the next "non recurring record" as opposed to the next record. The field the button needs to que from has groups of duplicate...
1
2282
by: vincentt via AccessMonster.com | last post by:
Hi all, I have a multi-table query, link to the following table: order table client info table receipt table discount card table I want to query multiple fields in the above table....
5
4989
AccessIdiot
by: AccessIdiot | last post by:
Argh! Just when I think everything is working and I am doing one final test before showing it to the guys I built the db for, Access throws out a weird message and won't let me add a record. But only...
6
3220
by: Chezza | last post by:
Hi All, Similar to many other posters, I don’t have a lot of experience with access (I'm using access 2003) and know little of VB, although I have picked up a bit while working on this project. ...
3
2471
gcoaster
by: gcoaster | last post by:
Hello! I am having problem with DLookup Function DLookup looks on form, and finds the combobox = cboFullName and then compares it to the column clientID in tblCLIENTS table. if they match,...
0
7198
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
7072
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
7271
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
7319
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...
1
6979
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...
0
7449
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
5570
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,...
0
4666
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...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.