Insert Row in GridView using SqlDataSource and update to database ?

Discussion in 'ASP .Net' started by Luqman, Nov 16, 2007.

  1. Luqman

    Luqman Guest

    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
    Luqman, Nov 16, 2007
    #1
    1. Advertising

  2. Luqman

    Manish Guest

    RE: Insert Row in GridView using SqlDataSource and update to database

    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
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    >
    Manish, Nov 19, 2007
    #2
    1. Advertising

  3. Luqman

    luqman Guest

    Re: Insert Row in GridView using SqlDataSource and update to database

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

    Best Regards,

    Luqman

    "Manish" <> wrote in message
    news:...
    > 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
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    luqman, Nov 20, 2007
    #3
  4. Luqman

    Manish Guest

    Re: Insert Row in GridView using SqlDataSource and update to datab

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

    >
    >
    >
    Manish, Nov 20, 2007
    #4
  5. Luqman

    Guest

    RE: Insert Row in GridView using SqlDataSource and update to database

    < 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
    ------------------- ----- ---- -- -
    , Nov 22, 2007
    #5
  6. Luqman

    luqman Guest

    Re: Insert Row in GridView using SqlDataSource and update to database

    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
    > ------------------- ----- ---- -- -
    >
    luqman, Nov 22, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGFiYmxlcg==?=

    insert row using Gridview and SqlDataSource?

    =?Utf-8?B?RGFiYmxlcg==?=, Mar 19, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    10,647
    =?Utf-8?B?RGFiYmxlcg==?=
    Mar 20, 2006
  2. mosscliffe
    Replies:
    3
    Views:
    9,438
    mosscliffe
    Apr 28, 2006
  3. Jason
    Replies:
    2
    Views:
    1,015
    Jason
    Nov 12, 2006
  4. Vaughn Haybittle
    Replies:
    0
    Views:
    886
    Vaughn Haybittle
    Apr 2, 2007
  5. Jason
    Replies:
    0
    Views:
    257
    Jason
    Nov 12, 2006
Loading...

Share This Page