Tuesday, February 1, 2011

Database Wizards

How to view the database in Visual Studio

From the view menu select Server Explorer.
At the top of Server Explorer right click on Database Connections
Choose new Database Connection
In the dialog box choose SQL Server Connection
In the next dialog box type localhost for server
in the drop down list for databases select the desired database
The database should show up in the server explorer
Click the little triangle beside it to expand it and veiw the tables and other database objects.

Wizards with databound controls

Drag a data bindable control such as a gridview onto the designer.
Click the little smart tag in the upper right corner
from the resulting menu choose data source/new data source
Choose SQL Database
If you have an existing connection string to the database you want to use, use it,
other wise choose new data string. It opens the dialog box where you enter
localhost and select the database
Once the connection string is established the dialog box opens where you
Select what table you want the data to come from.
You can select all or some of the fields
With the Where button you can set criteria for which rows to show
with the Sort button you can set the sort
With the advance you can set up Insert Update and Delete statements
Click next
Test you query
Finish

1 comment:

  1. Advanced courtesy of Chris

    Select LastName as [Last Name], FirstName as [First Name], CONVERT(nvarchar(50), DonationDate, 106) as [Donation Date], CONVERT(DECIMAL(12,2), DonationAmount) as [Donation Amount]
    From Person p
    Inner Join Donation d
    On p.PersonKey=d.PersonKey

    ReplyDelete