473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

DataGrid.Datasource

I have a class for DatabaseManager.cs that has all the connection path, add,
update, delete.I have a problem with the datagrid because I have a form that
contains the datagrid called frmAllProjects.cs, so how do I connected to my
dbmanager.cs from the form.
DatabaseManager Code:
OleDbConnection Conn = new OleDbConnection();
string sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=E:\\Freddy\\Projects\\vb.net\\Project Track It\\bin\\Project.mdb";
Conn.ConnectionString = sConnString;
Conn.Open();

string select = "select * from Project";
OleDbDataAdapter da = new OleDbDataAdapter (select, Conn);
DataSet ds = new DataSet();
da.Fill(ds);
frmAllProjects code: <-- this is the form Code
DatabaseManager manager = new DatabaseManager();
manager.path();
//Datagrid
dg1.Datasource = ds (); <-- I get the error here because ds is not found --
But when I have all the code on the datagrid it works fine.

Also I do not what th hardcode the data Source like this:
OleDbConnection Conn = new OleDbConnection();
string sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=E:\\Freddy\\Projects\\vb.net\\Project Track It\\bin\\Project.mdb";

I want to do this:
OleDbConnection Conn = new OleDbConnection();
string sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=Project.mdb"; <-- it does not work like this
Nov 17 '05 #1
1 3877
Hi Freddy,

The simplest solution would probably be to have the DatabaseManager class
keep a reference to the retrieved dataset and return the reference as a
read-only public property.
Obviously the form containing the grid must keep a reference to the
DatabaseManager instance during the form's lifetime.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]
"freddy" <fr****@discussions.microsoft.com> wrote in message
news:6C**********************************@microsof t.com...
I have a class for DatabaseManager.cs that has all the connection path,
add,
update, delete.I have a problem with the datagrid because I have a form
that
contains the datagrid called frmAllProjects.cs, so how do I connected to
my
dbmanager.cs from the form.
DatabaseManager Code:
OleDbConnection Conn = new OleDbConnection();
string sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=E:\\Freddy\\Projects\\vb.net\\Project Track It\\bin\\Project.mdb";
Conn.ConnectionString = sConnString;
Conn.Open();

string select = "select * from Project";
OleDbDataAdapter da = new OleDbDataAdapter (select, Conn);
DataSet ds = new DataSet();
da.Fill(ds);
frmAllProjects code: <-- this is the form Code
DatabaseManager manager = new DatabaseManager();
manager.path();
//Datagrid
dg1.Datasource = ds (); <-- I get the error here because ds is not
found --
But when I have all the code on the datagrid it works fine.

Also I do not what th hardcode the data Source like this:
OleDbConnection Conn = new OleDbConnection();
string sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=E:\\Freddy\\Projects\\vb.net\\Project Track It\\bin\\Project.mdb";

I want to do this:
OleDbConnection Conn = new OleDbConnection();
string sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=Project.mdb"; <-- it does not work like this


Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know...
1
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls...
3
by: CVerma | last post by:
Hi, I have an embedded datagrid within a datalist. I am not able to perfrom paging in the datagrid. Any ideas? Here is my code: Here is my Simplegrid.cs file: using System; using...
4
by: tshad | last post by:
I am having trouble with links in my DataGrid. I have Links all over my page set to smaller and they are consistant all over the page in both Mozilla and IE, except for the DataGrid. Here is a...
4
by: dyw55a | last post by:
Donna Mar 15, 10:11 am show options Newsgroups: microsoft.public.dotnet.framework.adonet From: "Donna" <dyw...@yahoo.com> - Find messages by this author Date: 15 Mar 2005 10:11:56 -0800...
1
by: jimb | last post by:
I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it. Anybody have a working example of a dropdownlist in an editable grid? Thanks. -- .....
4
by: Jan Nielsen | last post by:
Hi all I'm a former Access developer who would like to implement a many-to-many relation in about the same way you do in Access: With a subform and a combo box. Is it possible to use a...
17
by: A_PK | last post by:
I have problem databinding the DataGrid with DataView/DataSet after the filter... I create the following proceudre in order for user to filter as many as they want, but the following code is only...
0
by: Familjen Karlsson | last post by:
Hi I have downloaded some code and tried it and nothing happens with the datagrid. Explain what is wrong and what I have to do please. I have tried to Import the namespace Hamster and it didn't...
8
by: Brock | last post by:
I am trying to populate a Crystal Report from data in my DataGrid. The reason for this is that I want the user to be able to change values without updating the database, but still have their report...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.