I want to retrieve a single column from a table in a database and then the value retrieved has to be converted to a string!!
Please help!!!

Recommended Answers

All 4 Replies

and the database is ms access and VB is the language i use
please help! urgent

Well...

Your need to use OleDb data provider in order to connect to MS Access database.

Steps:

(1) Create OleDbConnection, OleDbCommand, OleDbDataReader
(2) Initialize Connection for e.g.
con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\emp.mdb;_
Persist Security Info=False") and con.open()
(3) Initialize Command object
cmd = New OleDbCommand("select ColumnName from Table", con)
(4) Execute Command dr = cmd.ExecuteReader
(5) Read Data
While dr.Read()
Type Cast all data and put in List for. e.g. string val = (string)dr(0)
End While
Catch
End Try
(6) Close Connection and Release objects

I want to retrieve a single column from a table in a database and then the value retrieved has to be converted to a string!!
Please help!!!

dataset ds=new dataset();
string str;
str=ds.tables[0].rows[0][0].tostring();

'Create Object of OleDb Connection
Dim con As OleDbConnection = New OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\emp.mdb;_
Persist Security Info=False")

'Connection is Open
con.open()

'Create Object of OledbCommand for execute Query
Dim cmd As OleDbCommand = New OleDbCommand("select ColumnName from Table", con)

Dim temp As String = Convert.ToString(cmd.ExecuteScalar())

For free C# controls visit http://sharpcontrols.wordpress.com

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.