Insert Row in GridView using SqlDataSource and update to database ?

L

Luqman

I added new rows to the GridView with the following code.

I am using SqlDataSource and Sql Server 2000 Northwind Database Customers
table.

Dim sqlarg As New DataSourceSelectArguments

Dim dv As New System.Data.DataView

dv = SqlDataSource1.Select(sqlarg)

Dim drNewRow As Data.DataRowView = dv.AddNew

drNewRow(0) = "LUQ1"

drNewRow(1) = "LUQMAN"

drNewRow.EndEdit()

GridView.DataSource=dv

GridView.DataBind()

The above code is just adding the row on the fly, but after adding various
rows, I want two choices.

1. Either Exit from the Web Form and Cancel all the updates.

2. Transfer the updated Rows, back to the Database.

How can I achieve the above Two Scenarios.

I want to Add/Edit Records within the Dataset, use them for calculations and
then finally update batch to the database or cancel the update.

Any idea please ?

Best Regards,

Luqman
 
M

Manish

You can add a new row to the Grid by adding a button in the footer and then
add the data and update the data in the database by clicking the update
button...

Regards,
Manish
 
L

luqman

My question is, what will be the coding behing Update Button, to update the
Database ?

Best Regards,

Luqman
 
M

Manish

You do not need to write code behind the update button. Infact, you will have
to write the SQL update query in the sqldatasource updateQuery property for
updating the database when you click the update button in the GridView
control.

Regards.
Manish
 
N

newbie

< snip >

<You can add a new row to the Grid by adding a button in the footer and then
<add the data and update the data in the database by clicking the update
<button...

<Regards,
<Manish


Ok - I'm about as new as new gets and am reading answers hoping I will learn something.


Placing an button in the footer "seems" simple enough if you mean putting a button from the toolbox
and placing it on the footer. If not please clarify. Also please explain what you mean by add the data as
in add it where? What update button are you referring to and where did it come from?

Sorry if I appear confused, but I'm obviously missing something here.

Alternatively, if you would like to post a sample page that would be even better.

thanks
 
L

luqman

Hi,

I want to add records on a fly, which will be saved in local dataset and
display in GridView Control, and as soon as I click on update button, all
the records will be transferred to the Database.

If I cancel, all the changes I made in local dataset will be removed from my
PC Local Memory or Dataset.

Best Regards,

Luqman

< snip >

<You can add a new row to the Grid by adding a button in the footer and then
<add the data and update the data in the database by clicking the update
<button...

<Regards,
<Manish


Ok - I'm about as new as new gets and am reading answers hoping I will learn something.


Placing an button in the footer "seems" simple enough if you mean putting a button from the toolbox
and placing it on the footer. If not please clarify. Also please explain
what you mean by add the data as
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top