Trying to understand the database in visual studio

Post number 7 has been selected as best answer.

Govind Sankar

Active member
Joined
May 15, 2020
Messages
27
Programming Experience
Beginner
Hi,
I am trying to learn database management system that exists in my company. I am new to this. So there are things that I have understood so far. I want to know what I understood is correct or not. So there is this Database which when I checked in Visual studio is of type Microsoft Sql Server. To begin with a dataset was created in visual studio. Then this Microsoft Sql Server Database was created using some kind of software that creates SQL Server Database. Then we connect this dataset we created in visual studio to this Sql Server Database using Visual Studio. So this is what I understood. Is this correct. Please tell me is this correct. Thank You.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,049
Location
Sydney, Australia
Programming Experience
10+
That's a very vague description. If you're actually talking about DataSets then the database would have to already exist. If you are using Entity Framework Code First then you can generate a database from that, but that's not a DataSet. You need to be a lot more specific in your description and terminology if you want us to confirm something as true, but you really ought to be asking the other people working in this system what it's doing.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
1,575
Location
Virginia Beach, VA
Programming Experience
10+
Sounds like our OP is talking about strictly typed DataSets that Microsoft was pushing back in 1990's before finally abandoning it because of poor developer adoption despite many self-styled architects hewing to it:
 

Govind Sankar

Active member
Joined
May 15, 2020
Messages
27
Programming Experience
Beginner
That's a very vague description. If you're actually talking about DataSets then the database would have to already exist. If you are using Entity Framework Code First then you can generate a database from that, but that's not a DataSet. You need to be a lot more specific in your description and terminology if you want us to confirm something as true, but you really ought to be asking the other people working in this system what it's doing.
The dataset is a .xsd file with different tables having different columns. Database is a microsoft sql server database and visual studio connects to it using ODBC. This much I am sure. Also there is the table adapter used to fill the dataset in the program. So is this fine. There is no one else working on it to ask doubts. The guy who did this project left the company and I am his replacement. He didnt do any documentation as well. So this forum and all of internet is where I look for help.
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
1,575
Location
Virginia Beach, VA
Programming Experience
10+
What book are you currently using to learn C#? What book are you using to learn the late 90's style typed datasets?
 

Skydiver

Staff member
Joined
Apr 6, 2019
Messages
1,575
Location
Virginia Beach, VA
Programming Experience
10+
The dataset is a .xsd file with different tables having different columns.
Yup, I was correct in my guess in post #3. If there is no one there at the office who knows how the system currently works, you'll have to become your own expert. Time to expense some books, or find a consultant to hire. As I said, it seems that only the architects went gaga over this way of building databases, but regular developers (and as I recall the DBAs as well), hated it.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,049
Location
Sydney, Australia
Programming Experience
10+
As suggested, you are using what is known as a "typed DataSet". That would have been generated from an existing database, not the other way around.

Using standard ADO.NET, you can create a data adapter as a broker between a database table and a DataTable in your application. You need to provide the SQL code and parameter definitions for that data adapter and all the data in the DataTable is accessed as an Object reference, because it needs to support any type of data.

Typed DataSets build on that standard ADO.NET base. The IDE tools will generate code that includes types that either inherit or wrap the standard types and add new members that is specific to your database, which is why it is generally generated from an existing database. You can make changes in the DataSet designer but that is generally modifications to the auto-generated types or additions, not building it from scratch.

With regards to the types, a standard DataSet has a Tables property that is a DataTableCollection and you can get a DataTable from it by providing a name as a String. A typed DataSet has a dedicated property for each DataTable and each of those DataTables is a dedicated type, based on the columns in the original database table. A standard DataTable has a Rows property that is a DataRowCollection. You can get a DataRow by indexing that collection and then you can use either index or column name to get data from a field as an Object reference. A typed DataTable can be indexed directly to get a typed DataRow and that DataRow has a dedicated property for each column that is already the correct type. For instance, instead of doing this with a standard DataSet:
C#:
string fullName = (string) myDataSet.Tables("Person").Rows(0)("FullName");
you would do this with a typed DataSet:
C#:
string fullName = myDataSet.Person(0).FullName;
You get full Intellisense for table and column names and everything is type-safe, hence the name "typed DataSet".

Instead of using data adapters that you build yourself, you use table adapters generated by the IDE. Generally speaking, you just need to call Fill to retrieve data and Update to save data. All the SQL code and parameter definitions are generated for you, in the form of a data adapter that is wrapped inside your table adapter. One nice feature is that you can use the same table adapter to execute full queries and also filtered queries. The default query, which is executed by calling Fill, is effective a "SELECT *" against the specified table. In the DataSet designer, you can add a query to the table adapter and add a filter or whatever other logic you like, as long as the result set has the same schema as the default query. Let's say that you have a Product table with a SupplierId column. The Fill method would retrieve every Product record. You could add a query like so:
SQL:
SELECT * FROM Product WHERE SupplierId = ?
and name the associated methods FillBySupplierId and GetDataBySupplierId. You can then call FillBySupplierId and provide an Id as an argument and get the filtered results in your typed DataTable.

This is just a basic primer. There's plenty more information out there if you search for "typed DataSets".
 

Govind Sankar

Active member
Joined
May 15, 2020
Messages
27
Programming Experience
Beginner
As suggested, you are using what is known as a "typed DataSet". That would have been generated from an existing database, not the other way around.
Thank You. I was away for a week since I was sick and that is why the late reply. So what I understood is dataset is created automatically from the database. So this database was created in Microsoft SQL Server Management Studio and then use visual studio to connect to it which will create the Dataset. Am I correct.
 
Top Bottom