System.Data.DataSet ds;
string sql = string.Empty;
List<string> myList;
try
{
//1. Open db connection
using (SqlConnection con = new SqlConnection(""))// '-- AppSettings.Get("db")
{
con.Open();
sql = "";// '-- 2.0 SQL statement.
using (SqlDataAdapter adapt = new System.Data.SqlClient.SqlDataAdapter(sql, con))
{
// 2.1 adapter parameters
adapt.SelectCommand.Parameters.Add("", SqlDbType.VarChar).Value = "";
ds = new DataSet();
//2.2 - fill data set
adapt.Fill(ds);
}
}
//3. Convert dataset to collection.
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
myList = new List<string>();
foreach (DataRow tempRow in ds.Tables[0].Rows)
{
myList.Add((string)tempRow[""]);
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
Basic SQL Adapter Setup
Page 1 of 10 Replies - 1380 Views - Last Post: 11 July 2019 - 02:33 PM
#1
Basic SQL Adapter Setup
Posted 11 July 2019 - 02:33 PM
The basic steps of returning data from a database, and dumping the dataset into a more bare bones collection for linq and other set things.
Page 1 of 1

New Topic/Question
Reply





MultiQuote

|