I have a datagridview which is filled with data from a table in a database. In the grid, the user clicks a row to edit that specific record. An edit screen is brought up, which has a text box for each field in the table, and the user can edit the data accordingly.
My question is... once the user is done editing, how can I reload/update the data in the datagridview without completely reloading the dataadapter and re-setting the source of the grid?
I tried
dataAdapter.update(dataset, "tablename"),
and setting the source of the grid to the dataset, but no updates are shown.
8 10881
You have to specify the key field thru which update could be made,like Ive specified here "sno"(here it is a parameter,it could be a control also)
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" DataSourceID="SqlDataSource1" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal">
<Columns>
<asp:CommandField ShowEditButton="True" />
</Columns>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"UpdateCommand="UPDATE [tablename] SET [location] = @location where (([sno]=@sno))" SelectCommand="SELECT [sno], [location] FROM [tablename]" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>">
<SelectParameters>
</SelectParameters>
<UpdateParameters>
<ASP:PARAMETER Type="Int32" Name="sno" /> </UpdateParameters>
</asp:SqlDataSource>
Alright, I have set the Primary Key column for the grid, but what is the command to update it?
the update command is thr see carefully..all u have to do is to set ur primary key or whatever condition in the where field(like ive done with "sno") -
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" DataSourceID="SqlDataSource1" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal">
-
<Columns>
-
<asp:CommandField ShowEditButton="True" />
-
</Columns>
-
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
-
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
-
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
-
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
-
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
-
<AlternatingRowStyle BackColor="#F7F7F7" />
-
</asp:GridView>
-
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"UpdateCommand="UPDATE [tablename] SET [location] = @location where (([sno]=@sno))" SelectCommand="SELECT [sno], [location] FROM [tablename]" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>">
-
<SelectParameters>
-
</SelectParameters>
-
<UpdateParameters>
-
<ASP:PARAMETER Type="Int32" Name="sno" /> </UpdateParameters>
-
-
</asp:SqlDataSource>
-
the update command is thr see carefully..all u have to do is to set ur primary key or whatever condition in the where field(like ive done with "sno") -
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" DataSourceID="SqlDataSource1" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal">
-
<Columns>
-
<asp:CommandField ShowEditButton="True" />
-
</Columns>
-
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
-
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
-
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
-
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
-
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
-
<AlternatingRowStyle BackColor="#F7F7F7" />
-
</asp:GridView>
-
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>"UpdateCommand="UPDATE [tablename] SET [location] = @location where (([sno]=@sno))" SelectCommand="SELECT [sno], [location] FROM [tablename]" ConnectionString="<%$ ConnectionStrings:ConnectionString2 %>">
-
<SelectParameters>
-
</SelectParameters>
-
<UpdateParameters>
-
<ASP:PARAMETER Type="Int32" Name="sno" /> </UpdateParameters>
-
-
</asp:SqlDataSource>
-
no no no, I don't want to use an update command. This is a very primitive way of doing this, and requires much more code!
Plus, I don't have a problem updating the database, what I need is to be able to update my datagridview without reloading the whole form, because this is very slow. Certainly someone out there has tried to do this before!!!
no no no, I don't want to use an update command. This is a very primitive way of doing this, and requires much more code!
Plus, I don't have a problem updating the database, what I need is to be able to update my datagridview without reloading the whole form, because this is very slow. Certainly someone out there has tried to do this before!!!
I've asked the same question a long time ago and never found a way to make this work. Everything I have tried hasn't worked...it seems as if the only way to update the dataGridView is to recreate the dataView (or whatever source you're using for the dataGrid)
My problem isn't that it takes too long to recreate the page, it's that I don't want to recreate my dataView becuase the user could have sorted it...recreating it would destroy whatever sort has been done on the view.
All I want to do, as I'm assuming all you want to do, is just change that one row in the dataView without recreating it. It doesn't seem like an unreasonable thing to do but everything I've tried thus far hasn't worked
If you figure this out please send me a PM
Thanks a lot!
Hello, guys.
Yep it's a problem. Some times ago I also looked for the solution, and have made the one but a bit specific: it’s suitable for .net desktop applications and only for Oracle database (of course it is temporary restriction).
Anyway it exists http://www.snotratech.com/snocnet.html :)
Best Regards,
Michael Milonov
Well thats fine and dandy, but I'm using microsoft sql server. I agree!! it seems like a very simple thing to do, and something that the developers would have seen useful, but I guess not!! I will keep digging, but for now I guess there is no answer?!
Anyway, concerning server-generated values this article may help:
http://www.devx.com/codemag/Article/20138/0/page/4
and if you use SQL server I heard about a new feature of SQL Server 2005, "notification services". Perhaps it may help also.
Best Regards,
Michael Milonov
Well thats fine and dandy, but I'm using microsoft sql server. I agree!! it seems like a very simple thing to do, and something that the developers would have seen useful, but I guess not!! I will keep digging, but for now I guess there is no answer?!
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Dave |
last post by:
I have a table with 3 fields of which the primary key is a autonumber. I have
created my dataadapter, dataset and datagridview using a wizard. However, in
the datagrid, the update and delete...
|
by: Rich |
last post by:
Hello,
Following an example at
http://www.vb-tips.com/dbpages.aspx?IA=DG (by Cor Lightert and Ken Tucker)
on binding a dataRelation to a Datagridview for sqlClient, I was able to
view rows...
|
by: Mitchell S. Honnert |
last post by:
Is there an equivalent of the DataGrid's DataGridTableStyle for the
DataGridView? If not, is there an easy way to duplicate the
DataGridTableStyle's functionality for the DataGridView?
Here's...
|
by: JeremyGrand |
last post by:
I've read what's available here, but can't seem to make this work right. I'm
experimenting with components on a form, although I'd rather create the
pieces & assemble them in code, but that's...
|
by: explode |
last post by:
I made nova oledbdataadapter select update insert and delete command and
connection veza. dataset is Studenti1data, I made it by the new data source
wizard,and made datagridview and bindingsource...
|
by: explode |
last post by:
I made a procedure Public Sub Novo(ByVal nova1 As String, ByVal nova2 As
String) that creates a new oledbDataAdapter with insert update select and
delete commads. I also added that commands can...
|
by: RafaulWolf |
last post by:
I have capture data from the serial port and save it in Access database using table adapter. I defined the serial port as a class so that I can use it dynamically as it require user to add multi...
|
by: Phil |
last post by:
VB2008
I have a DataGridView with MultiSelect = True and
SelectionMode=FullRowSelect. One of the columns is a checkbox column. I have
a function that goes through all the selected rows and sets...
|
by: bharathi228 |
last post by:
Hi,
iam working with windows application.here my requirement is binding data to database from a datagridview.
next i want to update some rows in datagridview and update it to the database.for...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |