Hi frnds i want to insert to data into database as
i have table as shown below with Table Name as T_MonthlyDays (i.e., from 01-31 days)
01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
and i would be collecting data from energy meter every data and data will stored once in a day,this storage will be done in above table .
Ex: If Today date is 16 and the data should stored in 16 of table and if it is 17 it should be stored in 17 of table and so on......
My code is as follows:
string checkDayMonth = "select column_name 'Column Name' from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='T_MonthlyDays'";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(checkDayMonth, conn);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
columndata = dr[0].ToString();
if (columndata == day)
{
value = columndata;
}
}
dr.Close();
conn.Close();
}
catch (Exception ex)
{
}
string sqlinsertdaychart = "insert into T_MonthlyDays(<unknown>) values where ('" + diffkwh + "')";
try
{
conn.Open();
SqlCommand cmdinsertdaychart = new SqlCommand(sqlinsertdaychart, conn);
cmdinsertdaychart.ExecuteNonQuery();
conn.Close();
}
catch (Exception ex)
{
}