troubleshooting Question

C# get result from Access database witout foreach loop

Avatar of kuzmar
kuzmarFlag for Slovenia asked on
4 Comments1 Solution775 ViewsLast Modified:
How can I get the row from my Access database without using foreach loop, because i only get 1 element at a time. Or is this necesary?
string connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\database.accdb;Persist Security Info=True";
string sql = "SELECT * FROM myTable WHERE ID = 5";

OleDbConnection conn = new OleDbConnection(connectionString);

OleDbDataAdapter adapter = new OleDbDataAdapter(sql, conn);
DataSet ds = new DataSet();

DataTable dt = ds.Tables[0];
foreach (DataRow dr in dt.Rows)
	elementid = int.Parse(dr["elementid"].ToString());
	title = dr["title"].ToString();
	content = dr["content"].ToString();
Freelance programmer / Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros