-
-
Save sin2akshay/03caf76de5e892841df68749b2ed262f to your computer and use it in GitHub Desktop.
C# - Calling a SQL Server Stored Procedure. Using a dataset to get the data.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string CS = ConfigurationManager.ConnectionStrings["test_connectionString"].ConnectionString; | |
using (SqlConnection con = new SqlConnection(CS)) | |
{ | |
SqlDataAdapter da = new SqlDataAdapter("testProcedure3", con); // Using a Store Procedure. | |
//SqlDataAdapter da = new SqlDataAdapter("SELECT 'this is a test text' as test", con); To use a hard coded query. | |
da.SelectCommand.CommandType = CommandType.StoredProcedure; // Comment if using hard coded query. | |
DataSet ds = new DataSet(); // Definition: Memory representation of the database. | |
da.SelectCommand.Parameters.AddWithValue("@ggg", 95); // Repeat for each parameter present in the Store Procedure. | |
da.Fill(ds); // Fill the dataset with the query data | |
GridView1.DataSource = ds; // Set the dataso... meh, you get it. | |
GridView1.DataBind(); | |
//TextBox1.Text=GridView1.Rows[0].Cells[0].Text; If you want to pass the data to another element. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment