471,066 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

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 1337
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by David Findlay | last post: by
reply views Thread by William Wisnieski | last post: by
1 post views Thread by vincentt via AccessMonster.com | last post: by
reply views Thread by leo001 | last post: by

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.