Sathya Narayan

Sathya Narayan

  • NA
  • 155
  • 63.7k

How to update using LINQ to SQL in vb.net

Aug 21 2014 2:02 AM
hi,

I would be using the LINQ to SQL to update using the query but i am not able to update the values using the linq. This is the code i had used to update so if any one can resolve the issue what i am facing.



Public Class Form1
    Dim context As New DataClasses1DataContext

    Dim emp As New tbl_empdetail
    Dim id As Integer
    Dim i As Integer
    Dim empId As Integer
    Dim dt As New DataTable
    Dim dr As DataRow
    Private dsource As BindingSource = New BindingSource()
    Private ds As DataSet = Nothing



  Private Sub button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button2.Click
      
        Try
            Dim q = (From emp In context.tbl_empdetails Where (emp.empid = id) Select emp).SingleOrDefault()


            emp.empid = Label7.Text
            emp.empname = textBox1.Text
            emp.empdesg = textBox2.Text
            emp.emp_sal = textBox3.Text
            emp.empmob = textBox4.Text
            emp.empemail = textBox5.Text
            emp.address = textBox6.Text
            context.SubmitChanges()
            'display()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

      
        MsgBox("Record Updated")
    End Sub


Plz can any one help???