ADO.NET SqlDataAdapter Class | DataTable & DataSet In ADO.NET | ADO.NET | Part-2
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
namespace SqlDataAdapterDemo
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter Id of any Employee : ");
int id = Convert.ToInt32(Console.ReadLine());
string cs = ConfigurationManager.ConnectionStrings["dbcs"].ConnectionString;
SqlConnection con = new SqlConnection(cs);
//SqlDataAdapter sda = new SqlDataAdapter("select * from employee_tbl",con);
SqlDataAdapter sda = new SqlDataAdapter("spGetEmployees",con);
//sda.SelectCommand = new SqlCommand("spGetEmployees",con);
sda.SelectCommand.CommandType = CommandType.StoredProcedure;
sda.SelectCommand.Parameters.AddWithValue("@id",id);
DataSet ds = new DataSet();
sda.Fill(ds);
foreach (DataRow row in ds.Tables[0].Rows)
{
Console.WriteLine("{0} {1} {2} {3} {4} {5}", row[0],row[1],row[2],row[3],row[4],row[5]);
}
Console.WriteLine("-----------------------------------------------------");
DataTable dt = new DataTable();
sda.Fill(dt);
foreach(DataRow row in dt.Rows)
{
Console.WriteLine("{0} {1} {2} {3} {4} {5}", row[0], row[1], row[2], row[3], row[4], row[5]);
}
Console.ReadLine();
}
}
}
.png)
.png)
.png)
.png)
.png)
.png)
.png)
Comments
Post a Comment