C# - Updating GridView Data Using LINQ?
Mar 24, 2011
I have a GridView which needs to get updated on RowUpdating Event. How can I update data using LINQ?
I am populating GV using LINQ too and here is the code for that:
protected void Page_Load(object sender, EventArgs e)
{
string getEntity = Request.QueryString["EntityID"];
int getIntEntity = Int16.Parse(getEntity);
using (OISLinq2SqlVs1DataContext dt = new OISLinq2SqlVs1DataContext())
[Code]....
View 1 Replies
Similar Messages:
Jan 28, 2011
I am just starting to use linq to sql for data access. It is working fine for read only. But it does not work for update. I have been reading the threads over several forums. It is clear that anonymous types (in my case var) cannot be updated. I cannot find what I should replace the var with and where I find it.
Below is the code. The exception is
Error 1 Property or indexer 'AnonymousType#1.date_last_logon' cannot be assigned to -- it is read only
fmcsaDataContext db = new fmcsaDataContext();
// DataTable _UserTable;
UserModel _UserModel = new UserModel();
var users = from u in db.FMCSA_USERs
where u.USER_NAME == pName && u.ACTIVE == true
select new
{
date_last_logon = u.DATE_LAST_LOGON,
date_current_logon = u.DATE_CURRENT_LOGON,
failed_login = u.FAILED_LOGIN,
};
if (users.Count() == 0)
return null;
foreach (var user in users)
{
user.date_last_logon = user.date_current_logon;
}
View 2 Replies
Dec 29, 2010
i want update record of Photo table with linq to sql so i create a sproc for it
i dispaly records of Photo table into the Gridview untill when user click on the update command
can updating selected row in a set of textbox
how can i fetch Fields value of selected row for put in the textboxs and updating them?
how can i bind DDLCategory(dropdownlist) to CategoryDatasource(LINQdatasource) with coding?
i want when i select cotegory from DDLCategory ,gridview has been changed?
[Code]....
View 1 Replies
Aug 30, 2010
My project includes a grid view with some updtable fields, some fields throw an error on update and some do not and it does not really make sense. WORK_STATION_ID does not cause an error, ROOM _ID cause an error, both are int? (I am using c#) and for update I use the code liste below.
[Code]....
[Code]....
View 1 Replies
Dec 14, 2010
I have a parent gridview which has a child gridview in the itemsTemplate. Both are binded to different SqlDataSources. I can successfully update and delete rows in the child gridview. After updating in the child gridview, some related data in the parent gridview are not updated automatically. So i have placed ParentGridview.Databind() in the rowupdated event of child gridview. But it doesnt look working.
How can i accomplish this?
View 4 Replies
Jan 27, 2010
[Code]....
[Code]....
View 1 Replies
Feb 20, 2011
I have a GridView with 5 fields. Only two of the fields are edittable (the others are READONLY).
I have an UpdateCommand as follows
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NHLPOOL %>"
SelectCommand="SELECT [PlayerID], [Firstname], [lastname], [Goals], [Assists], [Goals]+[Assists] as Points, [AsOfDate] FROM [PlayerStats], [Player] where [PlayerStats].[PlayerID] =[Player].[ID] ORDER BY Points DESC"
UpdateCommand="UPDATE PlayerStats SET Goals =@GOALS, Assists =@ASSISTS, AsofDate=GETDATE() WHERE PLAYERID = @PLAYERID">
</asp:SqlDataSource>
The issue is I want the PLAYERID GV column to be READONLY but I get a runtime error when updating if the PLAYERID is READONLY.
I get the error "
Must declare the scalar variable "@PLAYERID"."
View 1 Replies
Mar 16, 2011
Customer customer = (from c in db.Customers
where c.CustomerID == "ABCD"
select c).Single();
customer.Country = "Canada";
db.SubmitChanges();
How to Print the SQL statement being sent to database server by the above Linq Query?
View 3 Replies
Jan 28, 2010
I am using LINQ to SQL and on my DetailsView it updates fine but with my gridview it is not. Both I used template fields so I am not sure what the issue is?
[Code]....
[Code]....
[Code]....
I have been doing a lot of reading and searching and I cannot figure out why this is not working for me.
View 7 Replies
May 24, 2012
I get Object reference not set to an instance of an object
cmd.CommandText ="UPDATE TB1 SET c_amt=@c_amt,c_type=@c_type,regby=@regby,dt=@dt WHERE id=@ id"; cmd.Parameters.Add("@c_amt", SqlDbType.VarChar).Value = Convert.ToInt32(((TextBox)
Gridview1.Rows[e.RowIndex].Cells[2].Controls[0]).Text);
cmd.Parameters.Add("@c_type", SqlDbType.VarChar).Value = ((TextBox)Gridview1.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
cmd.Parameters.Add("@regby", SqlDbType.VarChar).Value = Session["name"];
cmd.Parameters.Add("@dt", SqlDbType.DateTime).Value = DateTime.Now.ToString("yyyy/MM/dd");UPDATE TBL1 SET c_amt='3000',c_type='E',regby='XYZ', dt='2012/05/24' WHERE id=94
by using in query analyzer i get it update but i had to put single quotes manually in date & amt ....
View 1 Replies
Feb 13, 2010
I have an asp.net page with a gridview control on it but I want to allow the user to also be able to update the selected row from a series of textboxes. I simply need the code for a button click event to do this.
button is called button1
textbox is called textbox1
gridview control is named gridview1
record to be modified is in 3rd column called PlayerName
The row to be edited will always be the only record shown and will always be selected by code I've already written. I will also need to know if the record must be set to edit mode to make the button click code work.
View 7 Replies
May 31, 2010
I'm just wondering if anyone has come across a good, easy method for updating a SQL Server 2000 DB table using the edit feature in GridView. The catch here is that I need it to encrypt, send to database, then decrypt when the page calls it to be displayed. I have successfully implemented an insert method using FormView with encryption. For some reason, I just can't seem to figure out the edit/update.
View 1 Replies
Feb 4, 2010
Duplicate Data in Gridview and Updating textbox in DetailsView
View 2 Replies
Mar 5, 2010
I have a gridview based on a sqldatasource that has some colums from which two colums showing the data of two fields: field1 and field2. field1 is an ID which should not be updated and therefore it is readonly=true. The sql-query from the sqldatasource is:
SelectCommand="SELECT field1, field2 from anyView"
What I want is, that when a row is updated, then the value from field1 should be copied to field2 The update-query is:
UpdateCommand="UPDATE myTable SET field2=@field2 WHERE field1=@field1"
My idea was, that the @field2 paramter gets the value from the query string out of field1:
<UpdateParameters>
<asp:QueryStringParameter Name="field2" QueryStringField="field1" Type="Int32" />
</UpdateParameters>
But this does not work. Is there an easy way to copy the data from field1 to field2 when updating the row? In addition, is this possible, even if field2 ist not shown in the gridview (i.e. field2 is selected in the query but is not a field in the gridview but should be updated with value of field1).
View 3 Replies
Jan 5, 2011
I have a requirement something as below.
1. I will click on the EDIT link in one of the grid view row. The row will change to edit mode
2. I will update the values and click update link in edit mode and edit mode closes.
3. At this point I need to capture the datakey of the updated row into some variable
View 3 Replies
Dec 9, 2010
I'm using ADO.Net code to access and update the data from the database. I'm using GridView for presentation. I wish to preserve old values of all the columns while updaing the records.
I'm using Code behind and not d Data Source controls. I wish to list the old records once record is updated.
View 5 Replies
Apr 9, 2010
I get the following error when I try to update rows in the DebtorList table : Invalid attempt to call FieldCount when reader is closed with LINQ
// Query the database for the row to be updated.//USE DL TEST VERSION...
var queryUpdateWithoutExclusions = (
[Code]....
View 1 Replies
Feb 14, 2010
regarding editing and updating the data in the gridview?
View 4 Replies
Feb 23, 2010
I was used TextBox in the GridView Then I Replace this textBox with Dropdownlist
and i fetched all the data from the database using DataSource in Editing Mode
But The problem is when i choose item from the dropdownlist to update it,it returns to Empty
(with No values) in the DropDownList??whats the problem?
[code]....
View 5 Replies
Sep 7, 2010
I have a gridview and I want to update a cell with a session variable username. In the Gridview1_RowEditing event I have this code :
GridView1.Rows(e.NewEditIndex).Cells(5).Text = Session("username")
It does not give me any errors and seems to work but the grid view cell do not take this session. When I'm clicking on the edit hyperlink this event is triggered.
View 5 Replies
Jun 6, 2010
I am trying to update gridview record, i am not getting any error but its not updating the record either.
[Code]....
View 4 Replies
Jul 30, 2010
Having a bit of difficulty working this gridview update problem out - I have managed to get edit/update function working but instead of only updating the current gridview row it is updating the whole table I believe this is due to a missing where statement on my Update statement - to single out the row index of my grid row.When I configure my sql datasource I am using custom statements Here is my update statement
UPDATE SimpData SET store_nbr = @store_nbr, date = @date, data_type = @data_type, acct_1 = @acct_1, amt_1 = @amt_1, acct_2 = @acct_2, amt_2 = @amt_2, acct_3 = @acct_3, amt_3 = @amt_3, cheque_nbr = @cheque_nbr, cheque_amt = @cheque_amt, gst_hst = @gst_hst, qst = @qst, comments = @comments, uploaded = @uploaded
Here is my gridview
<asp:GridView
ID="GridView1"
runat="server"
CellPadding="4"
Font-Names="Arial"
ForeColor="#333333"
GridLines="None"
Font-Size="Smaller"
Width="100%"
AllowPaging="True"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
OnRowCommand="GridView1_RowCommand"
OnRowEditing="GridView1_RowEditing"
OnRowUpdating="GridView1_RowUpdating"
AutoGenerateColumns="False"
DataSourceID="SqlDataSource1"
OnRowDataBound="GridView1_RowDataBound">
<RowStyle
BackColor="#EFF3FB"
/>
<FooterStyle
BackColor="#507CD1"
Font-Bold="True"
ForeColor="White"
/>
<PagerStyle
BackColor="#2461BF"
ForeColor="White"
HorizontalAlign="Center"
/>
<SelectedRowStyle
BackColor="#D1DDF1"
Font-Bold="True"
ForeColor="#333333"
/>
<HeaderStyle
BackColor="#507CD1"
Font-Bold="True"
ForeColor="White"
Font-Size="Smaller"
/>
<EditRowStyle
BackColor="#2461BF"
/>
<AlternatingRowStyle
BackColor="White"
/>
<Columns>
<asp:ButtonField
ButtonType="Button"
CommandName="Select"
HeaderText="Select item to delete"
ShowHeader="True"
Text="Delete">
<ControlStyle
Font-Size="Smaller"
/>
</asp:ButtonField>
<asp:CommandField
ShowEditButton="True"
/>
<asp:ButtonField
ButtonType="Button"
CommandName="Select"
HeaderText="Select item to upload"
ShowHeader="True"
Text="Upload">
<ControlStyle
Font-Size="Smaller"
/>
</asp:ButtonField>
<asp:BoundField
DataField="store_nbr"
HeaderText="Store Number"
SortExpression="store_nbr"
/>...............
View 2 Replies
May 3, 2010
i have a DropDownlist in my GridView that is bind to another DataSource than the GridView.
For the display it is working well but when I want to update datas I m stuck. Something is wrong and I don't know why.
[Code]....
I am stocking in the Database the value of the dsDroit but when I want to update the field I just know how to get the text not the value.
View 9 Replies
Oct 15, 2010
I have a gridview that holds 4 columns. in the fourth column there is a DropDownlist that holds three items.
I want my users to select one of the values and when they do the auto post back (which is set to true) should execute a method that updates the database selected row. But do i use the selectedindexchanged of the DDL or the Gridview? My head is totally thrashed so i imagine its really simple and im just over thinking it.
[Code]....
View 3 Replies
Jan 20, 2010
i wanted to refresh the gridview once user enters values and clicks update button. But its not updating. If i change my selection to pop up gridview, then it is showing the updated values. I dont know where i am doing wrong. can any one suggest changes in my code?
[Code]....
View 2 Replies