Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old April 25th, 2005, 04:29 AM
Registered User
Join Date: Apr 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Connection DataGrid to Access database

I'm fairly new to .NET and I have question:
How can I connect datagrid to the Access database? How can I do it? Is It possible?

Thank you.
Old April 25th, 2005, 04:59 AM
Friend of Wrox
Join Date: Apr 2005
Posts: 186
Thanks: 0
Thanked 0 Times in 0 Posts

Surely, sample C# code below

        string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=C:\\db1.mdb";
        System.Data.IDbConnection dbConnection = new System.Data.OleDb.OleDbConnection(connectionString);

        string queryString = "SELECT [test].* FROM [test]";
        System.Data.IDbCommand dbCommand = new System.Data.OleDb.OleDbCommand();
        dbCommand.CommandText = queryString;
        dbCommand.Connection = dbConnection;

        System.Data.IDbDataAdapter dataAdapter = new System.Data.OleDb.OleDbDataAdapter();
        dataAdapter.SelectCommand = dbCommand;
        System.Data.DataSet dataSet = new System.Data.DataSet();

        Datagrid1.DataSource= dataSet.Tables[0];

Similar Threads
Thread Thread Starter Forum Replies Last Post
Connection to Access Database in .Net KarthikR BOOK: ASP.NET Website Programming Problem-Design-Solution 1 January 16th, 2007 11:56 AM
How to make a connection with access database arshad mahmood Classic ASP Professional 1 April 18th, 2006 03:53 AM
DataGrid with access connection Sindhuja ASP.NET 1.0 and 1.1 Basics 0 January 21st, 2006 03:59 AM
Access Database connection widad Classic ASP Databases 3 November 5th, 2004 05:24 AM
Connection to a Access database aadz5 ASP.NET 1.0 and 1.1 Basics 2 October 13th, 2003 06:35 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.