Announcement

Collapse
No announcement yet.

creating stored procedures

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • creating stored procedures

    Hi to everyone i am a newbie to ms sql i am creating a stored procedure to retrive data for the logged user pls give me some examples.
    Thanx

  • #2
    Hey Vinay!

    Here is an example for you to retrieve data from a SQL-server table using a stored procedure.

    Code:
    string sCN = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
    
    SqlConnection sqlConnection2 = new SqlConnection(sCN);
    
    
    
     
    
    SqlCommand cmd = new SqlCommand();
    
    cmd.CommandType = System.Data.CommandType.Text;
    
    cmd.Parameters.AddWithValue("@userID", userID);
    
     
    
    Int32 rowsAffected;
    
    cmd.CommandText = "get_user";                                 //Stored procedure to get user data. Takes UserID as parameter
    
    cmd.CommandType = CommandType.StoredProcedure;
    
    cmd.Connection = sqlConnection2;
    
    
    
    sqlConnection2.Open();
    
    rowsAffected = cmd.ExecuteNonQuery();
    
    sqlConnection2.Close();
    Hope that helps!

    Comment

    Working...
    X