際際滷

際際滷Share a Scribd company logo
.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 TableFill in the BlanksID 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 databasethis.Validate();this.personBindingSource.EndEdit();this.tableAdapterManager.UpdateAll(this.diagramDataSet);
Howdo I?Delete row?PersonDataSet.PersonRow oldPersonRow;oldPersonRow = personDataSet.Person.FindBypersonID(index);oldPersonRow.Delete(); and dont 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();

More Related Content

Net database

  • 1. .NET DatabaseLecture by Benny Skogberg 06/29/10
  • 2. 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
  • 3. .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
  • 4. .NET Database Object ModelData Storage.NET Database ObjectsSELECT commandINSERT commandUPDATE command DELETE commandTableDataSet objectTable-Adapter objectDataSet objectDataSet objectDB diagram support objectsSQL DatabaseDatabasediagram
  • 5. Howto?Create a new Windows Forms ApplicationAdd Service-based databaseWhen asked: select Dataset
  • 6. Howto?Add New TableFill in the BlanksID is always primary key
  • 7. 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
  • 8. 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
  • 9. LayersSQL DatabaseToolBar objectBinding-Source objectDataSet objectTable-Adapter objectBinding-Navigator object
  • 10. 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 databasethis.Validate();this.personBindingSource.EndEdit();this.tableAdapterManager.UpdateAll(this.diagramDataSet);
  • 11. Howdo I?Delete row?PersonDataSet.PersonRow oldPersonRow;oldPersonRow = personDataSet.Person.FindBypersonID(index);oldPersonRow.Delete(); and dont forget to validate and write the change to database
  • 12. 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();