Avatar of jedistar
jedistarFlag for Singapore

asked on 

SQL server, connection, command, reader, adapter etc.

Hi,

How do i create a sqlconnection using windows authentication?
How do i write the sqlcommand to retrieve data from the table "products" where id = 5?
How do i use a data reader to read data from the above?
How do i use a dataadapter to read from table "products", passing it into a Dataset?
How do i write stored procedures using VS.NET 2003 or SQL SERVER?

Lastly, what is a typed dataaset and whats the diff between a normal ds and typed ds?
C#

Avatar of undefined
Last Comment
dstanley9
ASKER CERTIFIED SOLUTION
Avatar of dstanley9
dstanley9

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of dstanley9
dstanley9

Basic SQL Stored Procedure:

CREATE PROCEDURE GetProduct
@argProductID int
AS

SELECT * FROM Products WHERE ProductID = @argProductID



A Typed DataSet is a class that derives from DataSet that has defenitions for tables and type-safe properties for the columns of each table.

For example, a TypeDataSet for the Northwind database might have the following defenition for the Products table along with a bunch of other code:

public class NorthwindDataSet : DataSet
{  

   // Lost of DataSet management code
    public class Products : DataTable
    {
        public int ProuctID
        {
            get
            {
                //
            }
            set
            {
                //
            }
        }
        public string ProductName
        {
            get
            {
                //
            }
            set
            {
                //
            }

        }
        // other properties for each column
    }
}

These classes can be generated by adding a DataSet item to your project and dragging tables into it from the Server Explorer.
Avatar of jedistar
jedistar
Flag of Singapore image

ASKER

Thanks, just my first qn, you used:
"Integrated Security=SSPI;Data Source=localhost;Initial Catalog=Northwind;"

can i use this -> Server=localhost;Database=Northwind;Integrated Security=SSPI;

Or must they be used in groups
eg:

Group 1-> "Integrated Security=SSPI;Data Source=localhost;Initial Catalog=Northwind;"
Group 2-> "Server=localhost;Database=Northwind;User ID=sa;Password='';
Avatar of dstanley9
dstanley9

For the second syntax, use "Trusted_Connection=True" instead of "Integrated Security=SSPI"

So you can choose:

"Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI;"
   - or -
"Server=localhost;Database=Northwind;Trusted_Connection=True;"
   (both connection strings produces the same result)

The first syntax is what VS generates when you create a connection, so that's what I typically use.
C#
C#

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

98K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo