read values from database
Published: 14. December 2008 | Updated: 14. December 2008License: Microsoft Public License (MS-PL)
Categories: Databases
Tags: C# SQL
Snippet example shows how to read values from database
Import namespace
using System.Data.SqlClient;
Code
// create connection SqlConnection sqlConnection = new SqlConnection("..."); sqlConnection.Open(); // create command SqlCommand command = new SqlCommand("stored_procedure_name", sqlConnection); command.CommandType = CommandType.StoredProcedure; // execute reader SqlDataReader reader = command.ExecuteReader(); // get values while (reader.Read()) { object res = reader["column_name"]; }
| Send us feedback about this snippet » |





