Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8577541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:10:59+00:00 2026-06-11T20:10:59+00:00

Possible Duplicate: LINQ Single vs First Im new to Linq and want to learn

  • 0

Possible Duplicate:
LINQ Single vs First

Im new to Linq and want to learn it the best way, I have here 2 working update events for linq, thay do the same, but what way is the best and do i need to add something to make it better !?

Solution 1

Protected Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click
    Using db As New ThedatabaseconnectionDataContext()
        Try
            Dim TheUpdateID = DirectCast(FindControl("Textbox5"), TextBox).Text
            Dim getEditing As testtable = (From c In db.testtables Where c.test_id = TheUpdateID Select c).FirstOrDefault()
            If getEditing IsNot Nothing Then
                getEditing.test_cat = DirectCast(FindControl("Textbox1"), TextBox).Text
                getEditing.test_info = DirectCast(FindControl("Textbox2"), TextBox).Text
                getEditing.test_number = DirectCast(FindControl("Textbox3"), TextBox).Text
                getEditing.test_datetime = DirectCast(FindControl("Textbox4"), TextBox).Text
                db.SubmitChanges()
                'textBox1.Text = "Contact updated."
            End If
        Catch ex As Exception
            'Me.lblMsg.Text = ex.Message
        End Try
    End Using
End Sub

Solution 2

Protected Sub Button2_Click(sender As Object, e As System.EventArgs) Handles Button2.Click
    Using db As New ThedatabaseconnectionDataContext()
        Try
            Dim tbltest As Table(Of testtable) = db.GetTable(Of testtable)()
            Dim TheUpdateID = DirectCast(FindControl("Textbox5"), TextBox).Text
            Dim getEditing As testtable = tbltest.Single(Function(c) c.test_id = TheUpdateID)
            If getEditing IsNot Nothing Then
                getEditing.test_cat = DirectCast(FindControl("Textbox1"), TextBox).Text
                getEditing.test_info = DirectCast(FindControl("Textbox2"), TextBox).Text
                getEditing.test_number = DirectCast(FindControl("Textbox3"), TextBox).Text
                getEditing.test_datetime = DirectCast(FindControl("Textbox4"), TextBox).Text
                db.SubmitChanges()
                'textBox1.Text = "Contact updated."
            End If
        Catch ex As Exception
            'Me.lblMsg.Text = ex.Message
        End Try
    End Using
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T20:11:00+00:00Added an answer on June 11, 2026 at 8:11 pm

    Where to even start on this one…

    For a start, I know this is likely a test project, so apologies if you’re already doing this, but please make sure you’re using acceptable data tier hierarchies – your DBML should be in a separate project from your Presentation layer.

    But, to the question in hand. My preferred way of doing this is getting the data object and updating it on an object level. Such as (pseudo code / I’m a C# kinda guy!):

    private MyObject object;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        // Select usually be ID
        object = DataLayer.GetObject();
    
        if(!IsPostBack)
        {
             // Load object details for editing into presentation layer
             TextboxObjectName.Text = object.Name;
        }
    }
    
    protected void Button_Click(object sender, EventArgs e)
    {
         // Button click event - update object and send it to database
         object.Name = TextboxObjectName.Text;
    
         DataLayer.UpdateObject(object);
    }
    

    This makes use of object tracking, and the Daya Layer can then look like this:

    function void UpdateObject(MyObject obj)
    {
        using (TestDataContext db = new TestDataContext ())
        {
    
           db.MyObjects.Attach(obj);
    
           db.Refresh(RefreshMode.KeepCurrentValues, obj);
    
           db.SubmitChanges();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: build linq queries dynamically linq update query dynamically I have a method
Possible Duplicate: F# equivalent of LINQ Single This function should return the first element
Possible Duplicate: Linq performance for in-memory collection I have a web application with around
Possible Duplicate: Linq - Top value form each group I have data in the
Possible Duplicate: LINQ to SQL: Return anonymous type? I have a standard LINQ to
Possible Duplicate: To return IQueryable<T> or not return IQueryable<T> I have LINQ to SQL
Possible Duplicate: LINQ to MySQL - what is the best option? I've been looking
Possible Duplicate: LINQ - Where not exists I'm using LINQ2SQL and I want to
Possible Duplicate: Learning about LINQ Hi everyone, I just want to understand what exactly
Possible Duplicate: 'Contains()' workaround using Linq to Entities? Using LINQ in C#, I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.