0.3 Creating a Database, a Table, and Connecting to the Database Flashcards

1
Q

What are the steps to creating and connecting to a database?

A
  1. Create the database
  2. Create tables in the database
  3. Obtain the connection string
  4. Connect to the Database, using a data provider
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you create a database in ADO.net?

A
  1. Open Server explorer in visual studio
  2. Right click on data connections and select ‘add new connection’ and fill the following information:
    • Enter your server name
    • Choose windows authentication
    • Enter your database name
  3. Click ok
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you create a table in ADO.net?

A
  1. Find your database name in server explorer
  2. Expand the database folder
  3. Right click on the tables folder and select ‘add new table’
  4. Enter your table creation command as so:
    CREATE TABLE [dbo].[TableName] (
    [ColumnName] DATATYPE CONSTRAINTS,
    [COLUMNNAME] DATATYPE CONSTRAINTS
    )
  5. Click on the update button to create the database
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

In ADO.net how do you obtain the connection string for your database?

A

Right click on the database in server explorer, select properties, and find and copy the database connection string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do you connect to a database in ADO.net?

A

SqlConnection conn = new SqlConnection(‘connection string’);

SqlCommand cmd = new SqlCommand(“Sql Query”, conn);

conn.Open();

SqlDataReader reader = cmd.ExecuteReader();

How well did you know this?
1
Not at all
2
3
4
5
Perfectly