私の更新ボタンに関する問題があります。SQLデータベースの更新を開始する場所がわからず、SSMS Microsoftを使用してテーブルの科目を作成し、VS 2010のULTIMATEテーブルをLINQtoSQLとDATASETに変換するために、私は正常に私のデータベースに保存し、私のdatagridviewを更新する保存ボタンを作成しました。データベースの更新ボタンの作成方法
[ Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
If txtSubjectName.Text = "" Then
ErrorProvider1.SetError(txtSubjectName, "Subject Name Cannot be Empty!")
Exit Sub
ElseIf txtSubSName.Text = "" Then
ErrorProvider2.SetError(txtSubSName, "Subject Short Name Cannot be Empty!")
Exit Sub
End If
Dim db As New EMSDataContext
Dim SaveSubject = From C In db.Subjects
Where C.SubjectName = txtSubjectName.Text
Select C
If SaveSubject.Count <> 0 Then
MsgBox("Subject already exits!!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Alart!!")
Exit Sub
Else
Dim SaveNSubject As New Subject With {.SubjectName = txtSubjectName.Text, .ShortName = txtSubSName.Text}
db.Subjects.InsertOnSubmit(SaveNSubject)
db.SubmitChanges()
MsgBox("Subject added successfully!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Information")
End If
Registration_Load(sender, e)
txtSubjectName.Text = ""
txtSubSName.Text = ""
End Sub]
また、データベースからデータを正常に削除し、データグリッドビューを更新する[削除]ボタンもあります。
[Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
Dim A As New EMSDataContext
Dim B = From C In A.Subjects
Where C.ID = Val(DtgvSubject.CurrentRow.Cells(0).Value)
Select C
Try
A.Subjects.DeleteOnSubmit(B.FirstOrDefault)
If MsgBox("Are You Sure to Delete This Record?", MsgBoxStyle.Question + vbYesNo, "Question") = MsgBoxResult.Yes Then
A.SubmitChanges()
MsgBox("Record Deleted Successfully!", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Information")
txtSubjectName.Text = ""
txtSubSName.Text = ""
Registration_Load(sender, e)
Else
txtSubjectName.Text = ""
txtSubSName.Text = ""
Registration_Load(sender, e)
End If
Catch ex As Exception
MsgBox("Select a Record First!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "ALERT!!!")
End Try
If B.Count = 0 Then
MsgBox("Please select list to delete!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Alart!!")
End If
End Sub]
私も、私も成功しているこれをダブルクリック場合、私は私のサブジェクト名]テキストボックスと件名短縮名テキストボックスにセルの値を取得DataGridViewのセルのダブルクリックイベントを作成しました。
[ Private Sub DtgvSubject_CellDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DtgvSubject.CellDoubleClick
Try
Dim i As Integer
i = DtgvSubject.CurrentRow.Index
Me.txtSubjectName.Text = DtgvSubject.Item(1, i).Value
Me.txtSubSName.Text = DtgvSubject.Item(2, i).Value
Catch ex As Exception
MsgBox("No Values in the Cells!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Alert!!!")
Button17_Click(sender, e)
End Try
End Sub]
私の質問は、私はテキストボックスに値を取得した後、私のデータベースへの更新ボタンを作成し、それらを更新することができますどのように、変更の送信、私のDataGridViewを更新していますか?
を私に答えてください、私は私のポストが理解できることを望みます。 –