I am trying to change the below code as LINQ. But I am unable to do this, please guide me.
private void getData(AutoCompleteStringCollection dataCollection)
{
string connetionString = null;
SqlConnection connection ;
SqlCommand command ;
SqlDataAdapter adapter = new SqlDataAdapter();
DataSet ds = new DataSet();
connetionString = "Data Source=.;Initial Catalog=pubs;User ID=sa;password=zen412";
string sql = "SELECT DISTINCT [fname] FROM [employee]";
connection = new SqlConnection(connetionString);
try
{
connection.Open();
command = new SqlCommand(sql, connection);
adapter.SelectCommand = command;
adapter.Fill(ds);
adapter.Dispose();
command.Dispose();
connection.Close();
foreach (DataRow row in ds.Tables[0].Rows)
{
dataCollection.Add(row[0].ToString());
}
}
catch (Exception ex)
{
MessageBox.Show("Can not open connection ! ");
}
}