|
|
 |
 |
|
Join the Discussion
|
Is this the kind of article that helps you?
Let us know!
|
|
 |
 |
|
|
 |
 |
 |
|
|
 |
Download the code.
Imports System.Data.OleDb
Public Class frmAboutVBSpotlights
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Dim myOleDbDataAdapter As OleDbDataAdapter
Dim myDataSet As DataSet = New DataSet()
Dim myDataTable As DataTable = New DataTable()
Dim myOleDbConnection As OleDbConnection
Dim myCommand As OleDbCommandBuilder
Dim artKeySave As Integer
Private Sub frmAboutVBSpotlights_Load( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
myOleDbConnection = New _
OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;" _
& "User ID=Admin;Data Source={path}\AboutVB.mdb")
Try
myOleDbDataAdapter = _
New OleDbDataAdapter("select * from Articles", _
myOleDbConnection)
myOleDbDataAdapter.Fill(myDataTable)
lstAboutVBData.DataSource = myDataTable
lstAboutVBData.DisplayMember = "artTitle"
lstAboutVBData.ValueMember = "artKey"
Catch
Console.WriteLine("Error Opening {0}", _
myOleDbConnection.DataSource)
End Try
myCommand = New OleDbCommandBuilder(myOleDbDataAdapter)
End Sub
Private Sub cmdUpdate_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles cmdUpdate.Click
If Microsoft.VisualBasic.Left(cmdUpdate.Text, 5) = "First" _
Then
myOleDbDataAdapter.Fill(myDataSet, "Articles")
myDataTable = myDataSet.Tables("Articles")
Dim rowArticle As DataRow = myDataTable.NewRow()
rowArticle("artTitle") = txtTitle.Text
Try
rowArticle("artDate") = txtDate.Text
Catch
rowArticle("artDate") = Now()
End Try
rowArticle("artVB6") = chkVB6.CheckState
rowArticle("artVBNET") = chkVBNET.CheckState
rowArticle("artURL") = txtURL.Text
rowArticle("artDescription") = txtDescription.Text
myDataTable.Rows.Add(rowArticle)
myOleDbDataAdapter.Update(myDataSet, "Articles")
myDataSet.Tables("Articles").AcceptChanges()
cmdUpdate.Text = "Then, Select And Change An Article"
RefreshListBox()
ElseIf Microsoft.VisualBasic.Left(cmdUpdate.Text, 5) = "Then," _
Then
myOleDbDataAdapter.Fill(myDataSet, "Articles")
myDataTable = myDataSet.Tables("Articles")
Dim myChangeRow As DataRow = _
myDataTable.Rows(lstAboutVBData.SelectedIndex)
myChangeRow("artKey") = artKeySave
myChangeRow("artTitle") = txtTitle.Text
Try
myChangeRow("artDate") = txtDate.Text
Catch
myChangeRow("artDate") = Now()
End Try
myChangeRow("artVB6") = chkVB6.CheckState
myChangeRow("artVBNET") = chkVBNET.CheckState
myChangeRow("artURL") = txtURL.Text
myChangeRow("artDescription") = txtDescription.Text
Dim newDataSet As DataSet
newDataSet = myDataSet.GetChanges()
myOleDbDataAdapter.Update(newDataSet, "Articles")
myDataSet.Tables("Articles").AcceptChanges()
cmdUpdate.Text = "Finally, Select And Delete An Article"
RefreshListBox()
ElseIf Microsoft.VisualBasic.Left(cmdUpdate.Text, 5) = "Final" _
Then
myOleDbDataAdapter.Fill(myDataSet, "Articles")
myDataTable = myDataSet.Tables("Articles")
myDataTable.Rows(lstAboutVBData.SelectedIndex).Delete()
myOleDbDataAdapter.Update(myDataSet, "Articles")
myDataSet.Tables("Articles").AcceptChanges()
RefreshListBox()
End If
End Sub
Private Sub lstAboutVBData_SelectedIndexChanged( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles lstAboutVBData.SelectedIndexChanged
Dim myDisplayRow As DataRow = _
myDataTable.Rows(lstAboutVBData.SelectedIndex)
artKeySave = myDisplayRow("artKey")
txtTitle.Text = myDisplayRow("artTitle")
txtDate.Text = myDisplayRow("artDate")
chkVB6.Checked = myDisplayRow("artVB6")
chkVBNET.Checked = myDisplayRow("artVBNET")
txtURL.Text = Mid(myDisplayRow("artURL"), 2, _
Len(myDisplayRow("artURL")) - 2)
txtDescription.Text = myDisplayRow("artDescription")
End Sub
Private Sub RefreshListBox()
myDataSet = New DataSet()
myDataTable = New DataTable()
myOleDbDataAdapter.Fill(myDataTable)
lstAboutVBData.DataSource = myDataTable
lstAboutVBData.DisplayMember = "artTitle"
lstAboutVBData.ValueMember = "artKey"
End Sub
End Class
First page >
Changing Without Wizards > Page
1,
2,
3,
4,
5,
6
|