Sunday, November 14, 2010

How to use ms access 2007 stored data in my vb 2008 program?

+10 for the best answer!How to use ms access 2007 stored data in my vb 2008 program?
I've posted this a bunch, hope it helps you also...





Connecting to an access database:





Dim Connection As OleDb.OleDbConnection = New OleDb.OleDbConnection(';Provider=Microsof鈥?Source=c:\mydb.mdb;Jet OLEDB:Database Password=password';)

Dim Command As New OleDb.OleDbCommand



Connection.Open() 'open up a connection to the database

Command.Connection = Connection





Getting the values of multiple rows:







Dim ds As New Dataset

Dim da As New OleDb.OleDbDataAdapter

Dim row As System.Data.DataRow

Dim Count As Integer



da.SelectCommand = New OleDb.OleDbCommand(';SELECT *';, Connection)

da.Fill(ds, ';Table';) 'Fill the dataset, ds, with the above SELECT statement



Count = ds.Tables(';Table';).Rows.Count

Dim Values(Count) As String



While Count %26gt; -1

row = ds.Tables(';Table';).Rows.Item(Count)

Values(Count) = row.Item(0)

Count = Count - 1

End While









Executing a query with just one result:



Dim People As String



MyCommand.CommandText = ';SELECT `People` FROM `Rooms` WHERE ID = 1';

People = MyCommand.ExecuteScalar()





Updating the database:



MyCommand.CommandText = ';UPDATE `Users` SET `Address` = '431 Cat Ave.' WHERE `ID` = 3';

MyCommand.ExecuteNonQuery()



and in the end never forget:



Connection.close()





Some lines may be truncated, please visit my post on MSDN forums for more info: http://social.msdn.microsoft.com/Forums/鈥?/a>How to use ms access 2007 stored data in my vb 2008 program?
http://youranswers.andrewbolam.co.uk

A very informative website you can also get much information in website

No comments:

Post a Comment