473,785 Members | 2,938 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Insert Row in GridView using SqlDataSource and update to database ?

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

Dim dv As New System.Data.Dat aView

dv = SqlDataSource1. Select(sqlarg)

Dim drNewRow As Data.DataRowVie w = dv.AddNew

drNewRow(0) = "LUQ1"

drNewRow(1) = "LUQMAN"

drNewRow.EndEdi t()

GridView.DataSo urce=dv

GridView.DataBi nd()

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




Nov 16 '07 #1
5 13290
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 DataSourceSelec tArguments

Dim dv As New System.Data.Dat aView

dv = SqlDataSource1. Select(sqlarg)

Dim drNewRow As Data.DataRowVie w = dv.AddNew

drNewRow(0) = "LUQ1"

drNewRow(1) = "LUQMAN"

drNewRow.EndEdi t()

GridView.DataSo urce=dv

GridView.DataBi nd()

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




Nov 19 '07 #2
My question is, what will be the coding behing Update Button, to update the
Database ?

Best Regards,

Luqman

"Manish" <Ma****@discuss ions.microsoft. comwrote in message
news:69******** *************** ***********@mic rosoft.com...
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 DataSourceSelec tArguments

Dim dv As New System.Data.Dat aView

dv = SqlDataSource1. Select(sqlarg)

Dim drNewRow As Data.DataRowVie w = dv.AddNew

drNewRow(0) = "LUQ1"

drNewRow(1) = "LUQMAN"

drNewRow.EndEdi t()

GridView.DataSo urce=dv

GridView.DataBi nd()

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






Nov 20 '07 #3
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" <Ma****@discuss ions.microsoft. comwrote in message
news:69******** *************** ***********@mic rosoft.com...
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 DataSourceSelec tArguments
>
Dim dv As New System.Data.Dat aView
>
dv = SqlDataSource1. Select(sqlarg)
>
Dim drNewRow As Data.DataRowVie w = dv.AddNew
>
drNewRow(0) = "LUQ1"
>
drNewRow(1) = "LUQMAN"
>
drNewRow.EndEdi t()
>
GridView.DataSo urce=dv
>
GridView.DataBi nd()
>
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
>
>
>
>
>
>
>
>
>
>
>
>
>


Nov 20 '07 #4
< 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 '07 #5
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

<ne****@hotmail .comwrote in message
news:02******** **************@ news.astraweb.c om...
< 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 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
5042
by: Mike Kelly | last post by:
I've chosen to implement the "optimistic concurrency" model in my application. To assist in that, I've added a ROWVERSION (TIMESTAMP) column to my main tables. I read the value of the column in my select, remember it, and then use it in the update. It works just fine when I have full control of the whole process. I want to do the same for my GridView/SqlDataSource combinations. I typically select from a view and update the corresponding...
7
14820
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1 but how is this done now in asp.net 2.0?
0
2390
by: Mike P | last post by:
Where exactly are the updateparameters of a gridview picked up from? I have created 2 very similar gridviews and given the updateparameters the same names as in my edititemtemplates. Yet this method has worked for 1 gridview and failed for the second gridview. Here is my gridview : <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:XConnectionString %>" SelectCommand="ViewForecast"...
1
6134
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some label,textboxs,dropdownlists,radiobutton and checkbox asp standard controls. On the click event of the command button the data gets stored into the database. I have created the stored procedures for the insert,update,delete. I have...
1
10408
by: Evan M. | last post by:
Here's my GridView and my SqlDataSource <asp:GridView ID="ContactHistoryGrid" runat="server" AutoGenerateColumns="False" DataSourceID="ContactHistoryDS" DataKeyNames="JobHistoryID" OnRowCreated="ContactHistoryGrid_RowCreated" CssClass="GridViewTable" GridLines="None" CellSpacing="1" CellPadding="3" AllowSorting="True" AllowPaging="True"> <EmptyDataTemplate>
0
2224
by: lamolap | last post by:
i have 1 gridview , a dropdownlist inside a gridview and a commandfield of (edit, update and cancel) my gidview looks like this Edit Surname Initials ParkingBay CommandField Me Y dropdownlistvalue CommandField You m dropdownlistvalue i have 2 sqldatasource. the other one is for gridview and...
0
4063
by: troydixon | last post by:
Hello, I am new at this, and have been trying to insert data into a table by using the footer of a gridview (which I dont like) or by using a detials view on the same page that is doing the following: 1) gets query string from url and filters records (works great) via a Details View 2) shows notes that have been added to the record shown in the details view using a grid view, and it filters the data by looking at the ID that is selected in...
4
9790
by: mohaaron | last post by:
This seems like it should be simple to do but for some reason I have been unable to make it work. I would like to databind a SqlDataSource to a GridView during the click event of a button. This sounds easy but the next requirement is that the GridView is editable. So I have included the SelectCommand and the UpdateCommand on the SqlDataSource to allow the GridView to be editable. I have now been able to get the GridView to display data...
0
1676
BeemerBiker
by: BeemerBiker | last post by:
I was wondering if a command like "SqlDataSource1.insert()" can somehow give me the new index that was created when the insert took place. If the insert always occurs at the end of the dataset then I assume something like "...Count" could be used to figure out where the insert is going to take place. I am not sure if there is a "Count" in SqlDataSource. Unfortunately, I didnt see a callback for something like "ItemInserted" which would give...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10153
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9952
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7500
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.