[imports]
System.Data.OleDb
-----------------------------------------------------------------------
[read data from database]
Dim con As OleDbConnection, cmd As OleDbCommand, dr As OleDbDataReader
Try
con = New OleDbConnection
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\dbase.mdb"
con.Open()
cmd = New OleDbCommand("SELECT * FROM A_Table", con)
dr = cmd.ExecuteReader
While dr.Read
ListView1.Items.Add(dr("A_Field"))
End While
Catch ex As Exception
End Try
dr.Close()
con.Close()
-----------------------------------------------------------------------
[execute SQL query into database]
Dim con As OleDbConnection, cmd As OleDbCommand
cmdAdd.Enabled = False
Try
con = New OleDbConnection
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\dbase.mdb"
con.Open()
cmd = New OleDbCommand("INSERT INTO A_TABLE (A_FIELD) VALUES ('A_VALUE')", con)
cmd.ExecuteNonQuery()
Catch ex As Exception
End Try
con.Close()
Why am I putting this code here? It's because I might forget this in the future. So this blog serves as my code reference site.
[note to moronic/copy-paste junkie]
If you copy this ULTRA SIMPLE code into your coding without trying to understand it, I lose all faith with your ability in programming. You might as well venture into anything that requires less analytical thinking for a brighter future.
No comments:
Post a Comment