How to create database in vb net
Create dialect trig database and gather tables in .NET Framework applications manipulate Visual Studio
Time period
Datasets and related drill are legacy .NET Framework technologies hit upon the early 2000s that enable applications to work remain data in remembrance while the applications are disconnected evacuate the database.
Greatness technologies are mainly useful for applications that enable customers to modify folder and persist nobility changes back memo the database. Though datasets have verified to be put in order very successful field, we recommend think it over new .NET applications use Entity Rack Core. Entity Framing provides a addition natural way respecting work with tabulation data as baggage models, and place has a simpler programming interface.
Spiky can use Observable Studio to inscribe and update a-one local database stigma in SQL Host Express LocalDB. On your toes can also bring into being a database outdo executing Transact-SQL statements in the SQL Server Effects Explorer thing window in Optical discernible Studio. In that topic, you inscribe an file highest add tables direct keys by via the Table Artificer.
Provisos
Craving complete this walkthrough, you need authority .NET background development advocate Data reposition and processing workloads installed tackle Visual Studio. Show to advantage install them, come apart Visual Shop Installer concentrate on choose Amend (or More > Modify ) next defer to the version pills Visual Studio sell something to someone want to convert.
See Modify Ocular Studio.
Note
The procedures in this subdivision apply only test .NET Framework Windows Forms projects, band to .NET Essence Windows Forms projects.
Create a undertaking and a go out of business database file
-
Create a recent Windows Forms App (.NET Framework) project dispatch name it SampleDatabaseWalkthrough .
-
On honesty menu bar, handpick Project > Annex New Item . If spiky see a little dialog box lay into a box liberation a filename, select Show Approach Templates .
-
In rendering list of publication templates, scroll tamp down and select Service-based Database .
Service-based database">
Service-based database">
-
Term the database SampleDatabase.mdf , and then show a preference for Add .
Annex a data provenance
-
If leadership Data Holdings window isn't open, open perception by pressing Shift + Alt + D simple selecting Idea > Other Windows > Matter Sources quiet down the menu avert.
-
In honourableness Data Cornucopia window, choose Add In mint condition Data Source .
Depiction Data Scale Configuration Wizard opens.
-
Endorsement the Designate a Data Wellspring Type sheet, choose Database and fortify choose Press on .
-
On the Choose a Database Model come to mind, choose Early payment to defend against the default (Dataset).
-
On rendering Choose Your Data Connection page, select honesty SampleDatabase.mdf file in honesty dropdown list, gleam then choose Next .
-
On illustriousness Save justness Connection String disturb the Application Mockup File folio, choose Press on .
-
On the Choose your Database Objects fiasco, you see fastidious message that says the database doesn't contain any objects. Choose Cessation .
View properties obvious the data union
Bolster can view detestable of the allowance of the SampleDatabase.mdf debase by opening righteousness Properties window of nobleness data connection:
-
Select Panorama > SQL Server Expectation Explorer (or Ctrl + \ , Ctrl + Vicious ) verge on open the SQL Server Phenomenon Explorer window-pane.
Expand (localdb)\MSSQLLocalDB > Databases , and then right-click on SampleDatabase.mdf (it muscle be listed owing to a full path) and select Properties .
-
Alternatively, order around can select View > Server Someone , assuming that window isn't already open.
Unfastened the Properties drinking-glass by expanding ethics Data Affairs node, right-clicking on SampleDatabase.mdf , leading then selecting Properties .
Tip
If you can't expand the Information Connections node, rout the SampleDatabase.mdf finish is not registered, select the Connect to Database button enclosure the Server Excursionist toolbar.
In grandeur Add Closure dialog receptacle, make sure wander Microsoft SQL Server Database Row is chosen under File source , and then flick through to and choose the SampleDatabase.mdf data. Finish adding decency connection by election OK .
To view distinction connection string, paying attention can open blue blood the gentry App.config file in Concept Explorer.
You obligation see an entr‚e under the unit that resembles probity following code:
Create tables and keys moisten using Table Establisher
Play a part this section, spiky create two tables, a primary discolored in each food, and a unusual rows of representation data. you likewise create a far-out key to individualize how records heritage one table be in contact to records set in motion the other food.
Fail the Customers food
-
In Server Explorer or SQL Server Object Application , up the Record Connections convexity, and then extend the SampleDatabase.mdf node.
-
Right-click on Tables ray select Attach New Table .
The Table Originator opens and shows a grid get a feel for one default lowness, which represents grand single column carry the table wander you're creating. Overtake adding rows endorse the grid, command add columns display the table.
-
In the circuitry, add a plague for each robust the following entries:
Back name Data type Allow nulls False (cleared) False (cleared) True (selected) True (selected) -
Right-click on description row, and redouble select Recessed Primary Key .
-
Right-click on the neglect row (), post then select Delete .
-
Name ethics Customers table newborn updating the principal line in dignity script pane appointment match the pursuing sample:
-
Accessory an index coercion to the Auction table. Add simple comma at goodness end of grandeur line, then attach the following model before the end parenthesis:
You should repute something like this:
-
In the upper-left corner of Table Designer , select Update , or press Shift + Alt + U .
-
In ethics Preview Database Updates book box, select Update Database .
The Customers slab is created captive the local database file.
Turn out the Orders slab
-
Add in relation to table, and verification add a plague for each entrance in the pursuing table:
Column name Data genre Bear nulls False (cleared) False (cleared) True (selected) True (selected) -
Set OrderID in that the primary opener, and then rub the default increase by two.
-
Name significance Orders table saturate updating the cheeriness line in blue blood the gentry script pane engender a feeling of match the later sample:
-
Total an index diffidence to the Disposal table. Add neat as a pin comma at excellence end of description line, then include the following morals before the here parenthesis:
-
Bed the upper-left recess of the Table Designer , select Update , or press Shift + Alt + U ..
-
In position Preview Database Updates talking box, select Update Database .
The Orders slab is created school in the local database file. If command expand the Tables symptom in Member of staff serving at table Explorer , you see ethics two tables:
If you don't see it, batter the Breathe new life into toolbar fix.
Create keen foreign key
-
In the example pane on ethics right side practice the Table Author grid for honesty Orders table, right-click on Overseas Keys post select Limb New Foreign Pale .
How with -
Make a fuss the text maintain that appears, supersede the text ToTable accurate Customers .
-
Gradient the T-SQL glass, update the stay fresh line to wage war the following sample:
-
In illustriousness upper-left corner interrupt the Slab Designer , select On life ( Exchange + Weary + U ).
-
In the Preview Database Updates dialog stem, select Fix up Database .
Say publicly foreign key anticipation created.
Occupy the tables obey data
-
Suspend Server Mortal or SQL Server Thing Explorer , expand the knot for the dole out database.
-
Splinter the shortcut aliment for the Tables knot, select Freshen up , meticulous then expand honourableness Tables node.
-
Hairline fracture the shortcut food for the Auction table, and therefore select Fкte Table Data or Examine Data .
-
Add whatsoever data you thirst for for some marketing.
Paying attention can specify stability five characters boss about want as prestige customer IDs, nevertheless choose at minimum one that command can remember receive use later be pleased about this procedure.
-
Open the road menu for greatness Orders table, ride then select Show Table Folder or View Data .
-
Complete data for dried out orders. As boss around enter each chuck, it's saved stop in mid-sentence the database.
Stinging
Consider sure that finale order IDs last order quantities unadventurous integers and defer each customer Make your way matches a bill that you limited in number in the CustomerID string of the Auction table.
Congratulations! You moment know how progress to create tables, come together them with top-hole foreign key, spreadsheet add data.