Update Using Linq to sql

Does anyone help me for update the Db using Linq to Sql?

The Code is given below:

My GridView Source :

 

 <asp:GridView ID="gvProduct" runat="server" AutoGenerateColumns="False"
                     DataKeyNames="ProductID>
                    <Columns>
                    <asp:TemplateField>
                    <HeaderTemplate>Products</HeaderTemplate>
                    <ItemTemplate>
                     <%#Eval("ProductName")%>
                   
                    </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                    <HeaderTemplate>Unit Price</HeaderTemplate>
                    <ItemTemplate><%#Eval("UnitPrice")%></ItemTemplate>
                    </asp:TemplateField>
                     <asp:TemplateField>
                    <HeaderTemplate>Description</HeaderTemplate>
                    <ItemTemplate><%#Eval("Description")%></ItemTemplate>
                    </asp:TemplateField>
                     <asp:TemplateField>
                    <HeaderTemplate>Unit Price</HeaderTemplate>
                    <ItemTemplate><asp:LinkButton runat="server" ID="lnkDelete" Text="Delete"
                     CommandArgument="<%#((GridViewRow)Container).RowIndex %>" OnClientClick="javascript:return confirm('Are you sure you want to delete?');" OnCommand="Delete_OnClick"></asp:LinkButton></ItemTemplate>
                    </asp:TemplateField>
                  <asp:TemplateField>
                    <HeaderTemplate>Unit Price</HeaderTemplate>
                    <ItemTemplate><asp:LinkButton runat="server" ID="lnkUpdate" Text="Update"
                     CommandArgument="<%#((GridViewRow)Container).RowIndex %>" OnCommand="Update_OnClick"></asp:LinkButton></ItemTemplate>
                    </asp:TemplateField>
                                       </Columns>
                    </asp:GridView>
And my cs file is given below,
 
 
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Sample.LinqBLL;
using System.IO;

public partial class LinqSample : System.Web.UI.Page
{
    protected string ProductName;
    protected float UnitPrice;
    protected string Description;

    protected void Page_Load(object sender, EventArgs e)
    {

        
        if (!Page.IsPostBack)
        {
            loadProducts();
        }
    }
    protected void btnInsert_Click(object sender, EventArgs e)
    {
        ProductName = this.txtProductName.Text.Trim();
        UnitPrice = Convert.ToSingle(this.txtUnitPrice.Text.Trim());
        Description = this.txtDesc.Text.Trim();
        LinqBLL.Add(ProductName,UnitPrice,Description);
        loadProducts();
    }
    private void loadProducts()
    {
        this.gvProduct.DataSource=LinqBLL.Get();
        this.gvProduct.DataBind();
    }
    protected void Delete_OnClick(Object sender, CommandEventArgs e)
    {
        int rowindex = Int32.Parse(e.CommandArgument.ToString());
        int pid = Int32.Parse(this.gvProduct.DataKeys[rowindex].Value.ToString());
        LinqBLL.Delete(pid);
        loadProducts();
    }
    protected void Update_OnClick(Object sender, CommandEventArgs e)
    {
       
        int rowindex = Int32.Parse(e.CommandArgument.ToString());
        int pid = Int32.Parse(this.gvProduct.DataKeys[rowindex].Value.ToString());
     
     // What can i do here?  
        
    }
}
  
 
  
0
youvasanth
4/28/2009 7:18:08 AM
asp.net.futures 1064 articles. 0 followers. Follow

3 Replies
722 Views

Similar Articles

[PageSpeed] 26

Hi, you can use Stored procedure, use SP as your method from your Datacontextclass


Hope This One Can Help.
Thanks

To Be Happy Is To Be YourSelf

Please remember to mark my reply as answers if it's the answer to your question.
0
Sayre
4/28/2009 9:04:47 AM

 Thanx Mohammad Nizamuddin

I've got the solution...

By 

Vasanth U

0
youvasanth
4/28/2009 10:31:15 AM
Reply:

Similar Artilces:

Update Db using Linq to Sql
 Does anyone know how to update database using Linq to Sql?Thanx in advance,Vasanth U. Hi Friend, You can get solution from here   http://www.richardbushnell.net/index.php/2008/02/18/how-to-update-data-with-linq-to-sql/Thanks and regards,Er. Tarakhttp://Er-Tarak.BlogSpot.Com  Hi Tarak,Thanx for ur guidance.ByVasanth ...

Updating XMLDocument using Linq (VB.NET)
Hi, I'm trying to write a function to update an XML file using Linq in VB.Net but the values will not change.The XML file format is as follows<Node> <System name="eQuips"> <Details1>e-Commerce Access Request Form</Details1> <Details2>Service Delivery Admin</Details2> <Details3>Service Desk / eQuips</Details3> <Details4></Details4> </System> <System name="Me2u"> <Details1>Access Request</Details1> <Details2>Retail Sales Support</Details2&g...

Update Db Using Linq to Sql #2
 I have 3 textboxes for productname,unitprice,description, 1 button "Save" and one gridview for displaying the records.In gridview, I have one link button named "Update". When I click the link button, the productname,unitprice and description will be displayed in textboxes respectively. After that i change the values, when "Save"  button clicked, the values updated in Db.Does Anyone help me?Thanx in advance. By Vasanth U  First Create Linq-SQL Data Model for Selected Table. I assume that table Name is Product : productname,unitprice,...

Trouble updating a row using LINQ to SQL
I am developing a web application which retrieves data from an SQL database using LINQ to SQL extension methods. When a user registers, a record is inserted into a table called 'Members' which holds their details. 'Members' has a foreign key 'MemberID' which relates to another table called 'Profiles'. 'Profiles' has a column called 'Picture' which is initially left null, and after registration the user has the option of uploading a picture to be stored in this column as the Image binary data type.  Here is the eve...

LINQ to SQL/ADO.NET Entity Framework
For the last year I've mostly ignored linq to sql.  Not ignored because I wanted nothing to do with it but more because I was knee deep in projects that didn't really allow me to.  Now I'm looking into linq to sql and it seems like a wonderful technology, although I don't understand it fully.  However, I keep running into this "entity framework".  I'm reading up on some blogs here and there and I think I get the jist.  The entity framework sounds like the future for data access and linq to sql is going the way of the dodo...?  Sound...

Updating another table using linq to sql table.
Hi,After successfully saved the values from the Rent Table, I want to update the Status attribute from "Available" to "On Booking" for that particular bike.The Status attribute is taken from the Bike Table.And I'm using linq to sql to save the values from the Rent Table.Here is how I save the Rent table without updating the "Status" attribute:  using (DataClassesDataContext context = new DataClassesDataContext()) { Rent rent = new Rent { NRIC = nrictxtbox.Text, Bikeid = Convert.ToInt32...

Can variable be used in SQL UPDATE statement in VB.NET
Hy, i have this problem in vb.net: I must use a variable in SQL UPDATE statement, after SET statement, and i'm getting error. This is that line of code: Dim variable_name As StringDim variable As Integer Dim sqlString As String = ("UPDATE table_name SET " variable_name " = " & variable & " WHERE UserID = '" & UserID & "'")Dim cmdSqlCommand As New SqlCommand(sqlString, conConnetion) cmdSqlCommand.ExecuteNonQuery()   When I don't use a variable after SET statement, everything work fine. This code wor...

error updating excel spreadsheet using vb.net
I have written an application to handle invoices.  At the end of the process, they can print the voucher out as an excel spreadsheet.  It has been working and I have moved the application to production. I can't get the spreadsheet to update.  I get this error.  Operation must use an updateable query excel spreadsheet using vb.net  I think it is some sort of permission issue or something to do with the jet engine but I have tried everything I can think of. This generally means that the ASPNet user does not have the correct ("change") permissions to sav...

Linq Error
Can I have some insight on this error? I get the error in line 2 below:1 DoorScheduleDataContext db = new DoorScheduleDataContext(); 2 PeopleInCategory pic = db.PeopleInCategories.Single(p => p.CategoryID == int.Parse(ddlCategories.SelectedValue)); Here is the error:System.InvalidOperationException was unhandled by user code  Message="Sequence contains more than one element"  Source="System.Data.Linq"Basically I am trying to create a PeopleInCategory object from a CategoryID (a DropDownList value).PeopleInCategory was created with LINQ ...

when to use sql update and sql insert
I have a page where the user can update stock records. it has 5 x 5 text boxes. If the user has already entered stock before that stock will show up and they can change it and clicking the button it will update, however if they have just entered new data i would assume they would need to insert it, so how do i go about doing this? do i need to use both insert and update in the same sql string?Jeremy HusonSenior Network EngineerCarden Computers - PC Repair Brighton Hi,   Generally in such a situation we normally differentiate  the records for updation and inserion through the...

Linq error using Linq to SQL
I created a Linq to SQL class with a parent menu table and a one to many sub table. When a menu table item is deleted, I want it to delete the sub menu items:                 Dim dc As New sssMenuDataContext()                If menuId <> INVALID_ID Then                     Dim menuDetail = (From md In dc.sssMenus _     ...

How to Update when dynamic Select SQL by using SQLDatasouce In .net 2.0?
In Dot net 2.0 we change using SQLDataSource to Conect with SQLDB. Now for My case ,the Select SQL is dynamic when differnece user and parameters to the page, So if I want to Update the data input by user,then I must give Update/insert/delelte SQL to SQLDatasource's InsertCommand /UpdateCommand/DeleteCommand .  How to Generate the Insert/update/delete command for the SQLDataSource ? as in dot net 1.1 can use SQLCommandBuilder to generate it,but SQLCommandBuilder  just support DataAdeptor not for SQLDataSource, Could any body know how to do it when the SelectCommand is dynamic an...

How to save XML document in to SQL Server database using C#.net and LinQ concepts
I have tried to save the XML document to SQL Server db using C#.net/ASP.Net and LinQ, it failed to do so. can some one help me in doing this....I have to save the document as such and will have to retrieve it using the same LINQ and C#.net/ASP.net, can you plz help me ..... Thanks, Ramakrishna  Hi,RamakrishnaU can try This http://dotnetslackers.com/articles/xml/Easy-XML-to-SQL-Using-Linq.aspx RAGHAV MVP ASP/ASP.Net Read My Blog MARK THE POST AS ANSWER IF IT HELPS U. "Success doesn't come to you…you go to it."--Marva Collins "Success does not come to those w...

VB.NET Codebehind Code to Update SQL Server 2005 Using SQLDataSource Control?
Hi, I am a newbie in using ASP.NET 2.0 and ADO.NET.  I wrote a hangman game and want to record statistics at the end of each game.  I will create and update records in the database for each authenticated user as well as a record for the Anonymous, unauthenticated user.  After a win or loss has occurred, I want to programmatically use the SQLDataSource control to increment the statistics counters for the appropriate record in the database (note I don't want to show anything or get user input for this function). I need a VB.NET codebehind example that will show me how I sho...

Web resources about - Update Using Linq to sql - asp.net.futures

Windows Update - Wikipedia, the free encyclopedia
Windows Update is a service provided by Microsoft that provides updates for the Microsoft Windows operating system and its installed components, ...

Gizmodo.com Updates
Nobody should have to use a pay phone , natural disaster or no natural disaster. So if your gadgets are out of juice after Sandy, here’s a tiny ...

Lifehacker.com Updates
By Whitson Gordon Ever run into a situation where you have multiple wireless networks available, but one is clearly better than the other? WiFi ...

Facebook To Update Mobile Apps Every 4 To 8 Weeks
On the same day that Facebook released a bunch of mobile updates for Apple and Android devices , the social network also announced that it will ...

Game, App Update Roundup: Christmas 2015 Edition
As Christmas quickly approaches, mobile and Facebook developers have updated their games and apps with a variety of themed updates to celebrate ...

Fleksy update brings 3D Touch support for the iPhone 6s and more
One of the best third-party keyboard options available on the App Store, Fleksy , has just received an update to version 7.5 with a number of ...

Mazda CX-5 updates bring nav to more trim levels
Filed under: Mazda , Crossover Mazda updates the recently refreshed CX-5 with more standard equipment by adding navigation and a backup camera ...

David Bruton Injury: Updates on Broncos Safety's Leg and Return - Bleacher Report
... Kubiak announced on Monday that safety David Bruton will miss the remainder of the regular season with a fractured fibula . Continue for updates... ...

Regulators Accuse Oracle Of Deceiving Customers About Security Of Java Updates
... million personal computers using Oracle’s Java Platform Standard Edition were misled about the security of their devices after software updates ...

SportsNet Central Update: Garnett returns to Garden
... Login Search form Search 51° Main menu Home Celtics Patriots Red Sox Bruins Revolution More WRITERS Watch Shop NECN SportsNet Central Update: ...

Resources last updated: 12/23/2015 10:59:49 AM