:cry: Saving datatables into database

  • Thread starter Thread starter argeam
  • Start date Start date
A

argeam

Hi all,

What i'm trying to do is as follows:

1) 3 txtboxes, 1 Add button, 1 Submit button, 1 datagrid
2) when the page loads, the user will be able to type in texts in all
3 textboxes.
3) Then the user clicks on add button, the data that the user just
type will be shown in the datagrid.
4) the items will add on whenever user clicks on add.
5) then after which the user has finished with the adding then he will
click on submit button and only then the records in the datagrid will
be inserted/added into the database.

NOTE: All the while the datagrid is disconnected to the database its
only when the user clicks on submit then it will be connected to the
database. I'm using vb.net, asp.net, ado.net and sql server.

Hope there will be someone to help me as i've also been searching for
the ans for a few weeks. really appreciate that someone might be able
to help me! Thanks!
 
Hi Argeam,

Therefore you create a dataset with a table with 3 columns
You set the datasource of your datagrid to that dataset
When the user clicks the buttons you create a new row in the dataset and
moves the values to the datarow items and set the textboxes after that to ""
You add the datarow to the datatable, automaticly it appears in the grid.
When the user clicks the submitbuton you do a dataadapter update
Then you clear the table in your dataset and goes on.

That is all.in my opinion.

Cor
 
I totally agree with Cor, I'd just add that nothing is going to appear until
the postback returns ostensibly caused by the button click. You need to
take care to rebind the table with the new row to the grid so you'll
probably need to store it in Session state or some other mechanism...

On button click.

DataRow dro = GridsDataTable.NewRow();
dro[0] = FirstTextBox.Text;
dro[1] = SecondTextBox.Text;
//etc
GridsDataTable.Rows.Add(dro);

//This table needs to be the one that's bound to the grid after the postback
so make sure you handle this.

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
http://www.devbuzz.com/content/zinc_personal_media_center_pg1.asp
argeam said:
Hi all,

What i'm trying to do is as follows:

1) 3 txtboxes, 1 Add button, 1 Submit button, 1 datagrid
2) when the page loads, the user will be able to type in texts in all
3 textboxes.
3) Then the user clicks on add button, the data that the user just
type will be shown in the datagrid.
4) the items will add on whenever user clicks on add.
5) then after which the user has finished with the adding then he will
click on submit button and only then the records in the datagrid will
be inserted/added into the database.

NOTE: All the while the datagrid is disconnected to the database its
only when the user clicks on submit then it will be connected to the
database. I'm using vb.net, asp.net, ado.net and sql server.

Hope there will be someone to help me as i've also been searching for
the ans for a few weeks. really appreciate that someone might be able
to help me! Thanks!
 
:?: Hi all,

I'm new to ado.net and i'm also quite confused with all the
datatable, dataset, Dataadapter etc. I understand at least 50% of
your suggestion but i really hope that you will be able to help me
more by giving me example on your example. esp. cor's suggestions.
Thanks a lot. hope i'm not asking too much.

REALLY THANK YOU!!
 
Hi Argeam,

When you are new and you want to make asp applications, did you already
checked this, a lot of samples as you ask, walkthoughs and other support.

ASP resourcekit.

http://msdn.microsoft.com/asp.net/asprk/

Although because you use VB.net I would take this one which covers as far as
I have seen the same when it is VB.net but is more typical VB. (It does not
cover the scripting way from the SDK 1.1 which is as far as I remember me
also in the aspnet resource kit)

http://msdn.microsoft.com/vbasic/vbrkit/default.aspx

And if you have problems installing it
http://msdn.microsoft.com/vbasic/vbrkit/faq/#installvdir

I hope this helps a little bit?

Cor
 
Back
Top