Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Insert Row in GridView using SqlDataSource and update to database ?

Reply
Thread Tools

Insert Row in GridView using SqlDataSource and update to database ?

 
 
Luqman
Guest
Posts: n/a
 
      11-16-2007
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












 
Reply With Quote
 
 
 
 
Manish
Guest
Posts: n/a
 
      11-19-2007
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



"Luqman" wrote:

> 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
>
>
>
>
>
>
>
>
>
>
>
>
>

 
Reply With Quote
 
 
 
 
luqman
Guest
Posts: n/a
 
      11-20-2007
My question is, what will be the coding behing Update Button, to update the
Database ?

Best Regards,

Luqman

"Manish" <> wrote in message
news:698BA948-2AF9-416E-9EAE-...
> 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
>
>
>
> "Luqman" wrote:
>
> > 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
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >



 
Reply With Quote
 
Manish
Guest
Posts: n/a
 
      11-20-2007
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

"luqman" wrote:

> My question is, what will be the coding behing Update Button, to update the
> Database ?
>
> Best Regards,
>
> Luqman
>
> "Manish" <> wrote in message
> news:698BA948-2AF9-416E-9EAE-...
> > 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
> >
> >
> >
> > "Luqman" wrote:
> >
> > > 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
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> > >

>
>
>

 
Reply With Quote
 
newbie@hotmail.com
Guest
Posts: n/a
 
      11-22-2007
< 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






--
--------------------------------- --- -- -
Posted with NewsLeecher v3.9 Beta 2
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

 
Reply With Quote
 
luqman
Guest
Posts: n/a
 
      11-22-2007
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

<> wrote in message
news:0285a18e$0$17487$...
> < 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
>
>
>
>
>
>
> --
> --------------------------------- --- -- -
> Posted with NewsLeecher v3.9 Beta 2
> Web @ http://www.newsleecher.com/?usenet
> ------------------- ----- ---- -- -
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
1 Gridview. Dropdown A is column from database, Dropdown B is column from database, Data in A and B must be from same row. anonymoushamster@gmail.com ASP .Net 2 11-07-2007 12:40 PM
Problem Using SqlDataSource to automatically Update Value of item in Gridview Row Vaughn Haybittle ASP .Net Datagrid Control 0 04-02-2007 10:56 PM
Gridview row databound event - can't get past the 1st row of gridview maurban@gmail.com ASP .Net 5 10-13-2006 09:37 PM
GridView nested in DataList - refreshing corresponding DataList row after updating GridView row H5N1 ASP .Net 0 04-26-2006 11:41 PM
insert row using Gridview and SqlDataSource? =?Utf-8?B?RGFiYmxlcg==?= ASP .Net 2 03-20-2006 02:49 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57