V
VB Novice Hendri
Guest
How can I Save changes to data and allso add new record. I am using this code below to wiew data, thanks to Xingyu Zhao.
Public Class Form1
Private recipesLst As List(Of Recipe) = New List(Of Recipe)()
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\Test.accdb;"
Using cn As OleDbConnection = New OleDbConnection(connString)
cn.Open()
Dim cmdText As String = "SELECT RecipeID, RecipeName, OtherData FROM Eiergeregte"
Using cmd As OleDbCommand = New OleDbCommand(cmdText, cn)
Dim reader = cmd.ExecuteReader()
While reader.Read()
ListBox1.Items.Add(reader("RecipeName"))
recipesLst.Add(New Recipe With {
.RecipeID = Convert.ToInt32(reader("RecipeID")),
.RecipeName = reader("RecipeName").ToString(),
.OtherData = reader("OtherData").ToString()
})
End While
End Using
End Using
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
Dim recipeSelected As String = ListBox1.SelectedItem.ToString()
Dim result = recipesLst.Where(Function(x) x.RecipeName = recipeSelected).FirstOrDefault()
TextBox1.Text = result.RecipeID.ToString()
TextBox2.Text = result.RecipeName
TextBox3.Text = result.OtherData
End Sub
End Class
Class Recipe
Public Property RecipeID As Integer
Public Property RecipeName As String
Public Property OtherData As String
End Class
Continue reading...
Public Class Form1
Private recipesLst As List(Of Recipe) = New List(Of Recipe)()
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim connString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\Test.accdb;"
Using cn As OleDbConnection = New OleDbConnection(connString)
cn.Open()
Dim cmdText As String = "SELECT RecipeID, RecipeName, OtherData FROM Eiergeregte"
Using cmd As OleDbCommand = New OleDbCommand(cmdText, cn)
Dim reader = cmd.ExecuteReader()
While reader.Read()
ListBox1.Items.Add(reader("RecipeName"))
recipesLst.Add(New Recipe With {
.RecipeID = Convert.ToInt32(reader("RecipeID")),
.RecipeName = reader("RecipeName").ToString(),
.OtherData = reader("OtherData").ToString()
})
End While
End Using
End Using
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged
Dim recipeSelected As String = ListBox1.SelectedItem.ToString()
Dim result = recipesLst.Where(Function(x) x.RecipeName = recipeSelected).FirstOrDefault()
TextBox1.Text = result.RecipeID.ToString()
TextBox2.Text = result.RecipeName
TextBox3.Text = result.OtherData
End Sub
End Class
Class Recipe
Public Property RecipeID As Integer
Public Property RecipeName As String
Public Property OtherData As String
End Class
Continue reading...