open Connection to the Database with Password
Dim MyPath As String = Application.StartupPath & "\__mydb__.mdb"
Dim MyPassword As String = "passme"
Dim StrSQL As String = "Select * From MyTable"
Dim MyConnection As New
OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
MyPath & ";Jet OLEDB:Database Password=" & MyPassword)
MyConnection.Open()
This Saves data to a DataSet and then uses update method
against Database Source File
Dim MyCommand As New OleDbCommand(StrSQL, MyConnection)
Dim MyDataset As DataSet = New DataSet()
Dim MyAdapter As New OleDb.OleDbDataAdapter(StrSQL, MyConnection)
MyAdapter.Fill(MyDataset, "MyTable")
Dim MyDataRow As DataRow = MyDataset.Tables("MyTable").NewRow
Fill the data in Four Columns in the Database (Fields)
MyDataRow("1_Column") = Textbox1.Text
MyDataRow("2_Column") = Textbox2.Text
MyDataRow("3_Column") = Textbox3.Text
MyDataRow("4_Column") = Textbox4.Text
MyDataset.Tables("MyTable").Rows.Add(MyDataRow)
MyAdapter.Update(MyDataset, "MyTable")
MessageBox.Show("Data Saved..", "Saved",
if you want to write the data as well to XML file then you
include(this)before update method
MyDataset.WriteXml(Application.StartupPath & "\_MyXMLFile_.XML")
End Sub
End Class
Dim SQL As String
SQL = "SELECT * FROM MyTable WHERE LastName LIKE " & textBox1.Text.Replace("", "") & "%"
The resulting string looks like:
SELECT * FROM MyTable WHERE LastName LIKE jones%
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim MyConnection1 As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & MyPath & ";Jet OLEDBatabase Password=" & MyPassword)
Dim myDataReader As OleDbDataReader
Dim txt As String = "SELECT * FROM MyTab WHERE C_URL LIKE " & TextBox7.Text.Replace("", "") & "*"
Dim myOleDbCommand = New OleDbCommand(txt, MyConnection1)
MyConnection1.Open()
myDataReader = myOleDbCommand.ExecuteReader()
Do While (myDataReader.Read)
If (myDataReader.IsDBNull(0)) Then
MsgBox(myDataReader.GetString(1))
Console.Write("N/A" + Chr(10))
MsgBox("no data")
Else
Console.Write(myDataReader.GetInt32(4).ToString() + Chr(10))
MsgBox(myDataReader.GetInt32(4).ToString() + Chr(10))
End If
Loop
myDataReader.Close()
MyConnection1.Close()
End Sub