Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 22nd, 2012  |  syntax: None  |  size: 1.42 KB  |  hits: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Linq to SQL - SubmitChanges not working
  2. Public Class Form1
  3.  
  4.     Dim db As New MydbContext.MydbDataContext
  5.     Dim bs = New BindingSource
  6.     Dim Staff As New MydbContext.Employee
  7.  
  8.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  9.  
  10.         ' load employee data from MySQL db in datagrid
  11.  
  12.         Dim StaffQuery = From s In db.Employees Select s
  13.         bs.DataSource = StaffQuery
  14.         DataGridView1.DataSource = bs
  15.  
  16.         ' this works fine
  17.  
  18.     End Sub
  19.  
  20.     Private Sub DataGridView1_CellClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
  21.  
  22.         'create an instance of the object Staff with the ID and Name from the datagrid
  23.         'is there a better way to do this?
  24.  
  25.         Staff.EmployeeID = DataGridView1.Rows(e.RowIndex).Cells("EmployeeID").Value
  26.         Staff.Name = DataGridView1.Rows(e.RowIndex).Cells("Name").Value
  27.         MsgBox(Staff.EmployeeID & " " & Staff.Name)
  28.         TextBox1.Text = Staff.Name
  29.  
  30.         'this works fine
  31.  
  32.     End Sub
  33.  
  34.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  35.  
  36.         Staff.Name = TextBox1.Text   'edit the Name
  37.         MsgBox(Staff.EmployeeID & " " & Staff.Name)  ' this works - shows new Staff.Name from textbox
  38.         db.SubmitChanges()   ' this fails to make db changes
  39.  
  40.     End Sub
  41.  
  42. End Class