I am new to asp.net. I am trying to retrieve data from SQL Server in an asp.net website. This is the result of my table in SQL,
Day_Of_Week Product_Count
-----------------------------
Sunday 8
Monday 150
Tuesday 80
Wednesday 95
Thursday 345
Friday 229
Saturday 48
This is my code in c#,
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection(Settings.DatabaseConnectionString);
SqlCommand com = new SqlCommand("Select * from tblProducts");
com.CommandType = CommandType.Text;
com.Connection = con;
con.Open();
SqlDataAdapter da = new SqlDataAdapter(com);
da.Fill(dt);
int monday = Convert.ToInt32(dt.Rows[1]["Product_Count"]);
int tuesday = monday + Convert.ToInt32(dt.Rows[2]["Product_Count"]);
int wednesday = tuesday + Convert.ToInt32(dt.Rows[3]["Product_Count"]);
int thursday = wednesday + Convert.ToInt32(dt.Rows[4]["Product_Count"]) ;
int friday = thursday + Convert.ToInt32(dt.Rows[5]["Product_Count"]);
Now, if there are no records on Sunday, it does not display Sunday row and I have to change the c# code. Instead, I want to put a switch case or something so that if the day is Monday, then I can write dt.Rows[0], if the day is Tuesday, then dt.Rows[0], etc.
Let me know what would be the best option to do this. Any help will be appreciated.
Thanks.
the recent documentationso that we may learn something? What's wrong with usingDataTables?DataTables?