foz Posted June 8, 2004 Posted June 8, 2004 Hi all I'm trying to append the current date/time to a table that's dynamically created. In the end i'd like it to be something along the lines of backup_01/01/2004. I'm trying the following, using c# in the codebehind, DateTime dt = DateTime.Now; strCommand = "select * into backup_"+dt.Date.ToString()+" from tbl"; sqlComm = new SqlCommand(strCommand, sqlConn); sqlConn.Open(); sqlComm.ExecuteNonQuery(); sqlConn.Close(); I keep getting errors with the forward slashes in the dt.Date. Has anyone done this before? I know that you can use forward slashes in names for tables but this seems to be giving me trouble. cheers foz Quote brown m+m, green m+m, it all comes out the same in the end
foz Posted June 8, 2004 Author Posted June 8, 2004 sorry disregard this, I found the solution. Just wrap the date in square brackets as follows: strCommand = "select * into [backup_"+dt.Date.ToString()+"] from tbl"; maybe this can help someone in the future. foz Quote brown m+m, green m+m, it all comes out the same in the end
*Experts* Nerseus Posted June 8, 2004 *Experts* Posted June 8, 2004 While you can surround the field name and put almost anything in there for a table (or column) name, the should factor might stop you :) Why not just format the date without slashes? A well formatted date with year first allows for easy sorting as a string (if you ever wanted to show a list of backups, for example): dt.Date.ToString("yyyyMMdd") -nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.