0

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!!!

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by MARKAND911
0

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

0

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

0

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();

0
'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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.