|
-
Apr 6th, 2008, 06:13 PM
#1
Thread Starter
Addicted Member
[2005] Filling Datagridview
Hi all,
I'm having a bit of a problem. It probably has an easy solution, but I don't see it.
Anyway, I am currently developing an application, and having trouble with deciding how to get data into the gridview.
The first thing I thought about was creating a class like "Griddata", and I would set it up like this....
Code:
Public Class Griddata
declare variables here
public property FirstName as String
Get, Set, etc.
Then, I would call a separate sql statement to determine the value(s) of each property.... for example,
Code:
private function returnFirstName (etc.)
firstname = select firstname from tablename
return firstname
Is this the way I should go about this? Seems to me like I'm way off. Oh, and I have an example, but the program was written by a contractor and the code is very confusing.
Will I be able to use a dataset? I ask because the program cannot access the database directly, and all the examples I've seen seem to have a SQLConnection string.....I'm sending my SQL requests through an intermediary.
-
Apr 6th, 2008, 06:48 PM
#2
Re: [2005] Filling Datagridview
It doesn't matter how you get your data. You can still bind it to the grid. If you have a DataTable, whether it's in a DataSet or not, then you can bind that DataTable to the grid. It doesn't matter whether you create and populate the DataTable yourself or you get it from elsewhere. A DataTable is a DataTable.
You don't need a DataTable either. Any list of data can be bound to the grid. Even if you create and populate the DataTable yourself you might still choose to transfer the data into a collection of business objects. Alternatively you might be receiving a collection of business objects from elsewhere. No sweat. Bind away.
Data-binding has nothing whatsoever to do with databases or data access. Data-binding is a very flexible mechanism that allows you to bind any IList or IListSource object to a control. Often the data in that object will have come from a database but there is no requirement for it to be so. Also, the DataTable class implements the IListSource interface, and therefore supports data-binding, but it is far from the only example. Almost every collection class in the Framework implements IList, so almost every collection class can be data-bound. The Array class also implements IList, so one-dimensional arrays can also be data-bound.
-
Apr 6th, 2008, 08:34 PM
#3
Thread Starter
Addicted Member
Re: [2005] Filling Datagridview
Now that I've researched it more....
I suppose my question is how do I fill the dataset if my "connection string" resides in an app.config file?
I'd also like to make sure that the dataset won't "lock" the database.
Last edited by Blakk_Majik; Apr 6th, 2008 at 08:50 PM.
-
Apr 6th, 2008, 09:54 PM
#4
Re: [2005] Filling Datagridview
You can get at connection strings in the config file using the ConfigurationManager class and its ConnectionStrings property.
DataSets were created specifically to be disconnected from the data source so, no, using one will not lock any database records or tables. The drawback is that if multiple users are accessing the data you have to allow for concurrency issues.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|