C#: how to get data from DB using console application
C#: how to get data from DB using console application
//---------------------------------------------Source code -------------------------------------------
private void showAll() {SqlConnection con = new SqlConnection(constring);
//Open database connection to connect to SQL Server
con.Open();
//Data table is used to bind the resultant data
DataTable dtusers = new DataTable();
// Create a new data adapter based on the specified query.
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM Feetable ", con);
//SQl command builder is used to get data from database based on query
SqlCommandBuilder cmd = new SqlCommandBuilder(da);
//Fill data table
da.Fill(dtusers);
DataTable table = dtusers;
foreach (DataRow row in table.Rows)
{
Console.WriteLine("*************************** Recod *********************");
foreach (var item in row.ItemArray)
{
Console.Write("Column : "); // Print label.
Console.WriteLine(item);
}
}
con.Close();
}
//----------------------------------------------------------END-------------------------------------------
By Hafiz Muhammad Umar Hayat
Comments
Post a Comment