I am trying to use a switch
statement by accessing data in the DataTable
using SqlDataAdapter
but not sure how to access the fields using switch statement.
Here is what I have started:
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myconnectionstring"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("SELECT NAME, DEPARTMENT, LOCATION from MyTable WHERE ID = @ID", con);
DataTable dt= new DataTable();
da.SelectCommand.Parameters.AddWithValue("@ID", int.Parse(ID));
da.Fill(dt);
DataRow row = dt.Rows[0];
here is where I get lost and I am sure the switch statement below is not the right syntax
switch (dt[0].Location)
{
case 1:
lblStage.Text = dt[0].Location.ToString() + " - It has been completed.";
break;
}