Please define "not working" and provide any error messages you are receiving.
builder.Append("select datepart(dd, datetime) as 'Day', datepart(hh,datetime) as 'Hour', count(*) as 'Count' ");
builder.Append("from @.table_name with (nolock) ");
builder.Append("where datetime > @.date_time ");
builder.Append("group by datepart(dd, datetime), datepart(hh, datetime) ");
builder.Append("order by datepart(dd, datetime), datepart(hh, datetime");dateTime = DateTime.Now.ToLongTimeString() + " " + DateTime.Now.ToLongTimeString();
cmd.CommandType = CommandType.Text;
cmd.CommandText = builder.ToString();
cmd.Parameters.Add("@.table_name", tableName);
cmd.Parameters.Add("@.date_time", dateTime);
I believe the problem is likely that you are attempting to use a parameter for the table name, which will not work and will generate an error from SQL Server. SQL Server does not provide for a variable as the table name in a query. You will instead need to append that table name as part of your string builder.
Terri|||Check out this tutorial on parameterized queries:
http://aspnet101.com/aspnet101/tutorials.aspx?id=1
No comments:
Post a Comment