First establish the DB connection string in app config. In the c# code you can simply pass the Stored Procedure to sql command with the connection string, in my sample method it is "au_ad_sync" (In this stored procedure I have used a simple select statement which brings out few records from the database). We'll next see how we can read the data and print in VS Output window.
References:
using System.Data.SqlClient;
using System.Configuration;
Make sure that you close the sql connection after using the SqlReader. (Simple but may miss out.). In above code I have used reader[0]. This will bring the values of the first column that Stored Procedure brings up.
No comments:
Post a Comment