.NET DatabaseLecture by Benny Skogberg 06/29/10
What is a Database?More correct it is a Database Management System (DBMS) Read moreA persistent container of DataStores any data type (Integer, String, Boolean, DateTime, Image,…)Since the 1970sStores data in tablesDatabaseDatabase table: Person
.NET Database Object Model.NET Visual Objects.NET Database ObjectsSystem.Windows.Form objectData entry objectBinding-Source objectSELECT commandINSERT commandUPDATE command DELETE commandToolBar objectDataSet objectTable-Adapter objectBinding-Navigator objectDatabase diagram
.NET Database Object ModelData Storage.NET Database ObjectsSELECT commandINSERT commandUPDATE command DELETE commandTableDataSet objectTable-Adapter objectDataSet objectDataSet objectDB diagram support objectsSQL DatabaseDatabasediagram
Howto?Create a new Windows Forms ApplicationAdd Service-based databaseWhen asked: select Dataset
Howto?Add New Table”Fill in the Blanks”ID is always primary key
Primary Key?A primary key is the unique reference to that rowIn never nullA foreign key can be a reference to a primary key in another tableprimary keys Person has a pair of shoes, but the shoe is stored in the Shoe table. Shoe column must have the same type as primary key in Shoe tableforeign key
Let the Fun Begin!Hit the Data menu > Show Data SourcesDrag-n-drop the table to the Windows Form and a DB-connected DataGridView is addedDetails show up too, if chosen
LayersSQL DatabaseToolBar objectBinding-Source objectDataSet objectTable-Adapter objectBinding-Navigator object
Howdo I?Add a new row?PersonDataSet.PersonRow personRow;personRow = personDataSet.Person.NewPersonRow();personRow.ID = index;personRow.Name = name;personRow.Age = age;personRow.Gender = gender;this.personDataSet.Person.Rows.Add(personRow);… validate and write to database…this.Validate();this.personBindingSource.EndEdit();this.tableAdapterManager.UpdateAll(this.diagramDataSet);
Howdo I?Delete row?PersonDataSet.PersonRow oldPersonRow;oldPersonRow = personDataSet.Person.FindBypersonID(index);oldPersonRow.Delete();… and don’t forget to validate and write the change to database
Read from the database?Read database rowPersonDataSet.PersonRow personRow;personRow = personDataSet.Person.FindBypersonID(index);int id = personRow.ID;String name = personRow.Name;int age = personRow.Age;String gender = personRow.Gender;slideShow.EndEdit();

Net database

  • 1.
    .NET DatabaseLecture byBenny Skogberg 06/29/10
  • 2.
    What is aDatabase?More correct it is a Database Management System (DBMS) Read moreA persistent container of DataStores any data type (Integer, String, Boolean, DateTime, Image,…)Since the 1970sStores data in tablesDatabaseDatabase table: Person
  • 3.
    .NET Database ObjectModel.NET Visual Objects.NET Database ObjectsSystem.Windows.Form objectData entry objectBinding-Source objectSELECT commandINSERT commandUPDATE command DELETE commandToolBar objectDataSet objectTable-Adapter objectBinding-Navigator objectDatabase diagram
  • 4.
    .NET Database ObjectModelData Storage.NET Database ObjectsSELECT commandINSERT commandUPDATE command DELETE commandTableDataSet objectTable-Adapter objectDataSet objectDataSet objectDB diagram support objectsSQL DatabaseDatabasediagram
  • 5.
    Howto?Create a newWindows Forms ApplicationAdd Service-based databaseWhen asked: select Dataset
  • 6.
    Howto?Add New Table”Fillin the Blanks”ID is always primary key
  • 7.
    Primary Key?A primarykey is the unique reference to that rowIn never nullA foreign key can be a reference to a primary key in another tableprimary keys Person has a pair of shoes, but the shoe is stored in the Shoe table. Shoe column must have the same type as primary key in Shoe tableforeign key
  • 8.
    Let the FunBegin!Hit the Data menu > Show Data SourcesDrag-n-drop the table to the Windows Form and a DB-connected DataGridView is addedDetails show up too, if chosen
  • 9.
    LayersSQL DatabaseToolBar objectBinding-SourceobjectDataSet objectTable-Adapter objectBinding-Navigator object
  • 10.
    Howdo I?Add anew row?PersonDataSet.PersonRow personRow;personRow = personDataSet.Person.NewPersonRow();personRow.ID = index;personRow.Name = name;personRow.Age = age;personRow.Gender = gender;this.personDataSet.Person.Rows.Add(personRow);… validate and write to database…this.Validate();this.personBindingSource.EndEdit();this.tableAdapterManager.UpdateAll(this.diagramDataSet);
  • 11.
    Howdo I?Delete row?PersonDataSet.PersonRowoldPersonRow;oldPersonRow = personDataSet.Person.FindBypersonID(index);oldPersonRow.Delete();… and don’t forget to validate and write the change to database
  • 12.
    Read from thedatabase?Read database rowPersonDataSet.PersonRow personRow;personRow = personDataSet.Person.FindBypersonID(index);int id = personRow.ID;String name = personRow.Name;int age = personRow.Age;String gender = personRow.Gender;slideShow.EndEdit();