The following is the code I’m using. I can save the new table with the name I give it in the command line, but how can I include the current user name as part of the table name? Can someone please help?
Dim Unm As String = Membership.GetUser(RegisterUser.UserName).UserName.ToString()
Dim tNm As String = (Unm & "JE").ToString()
'Connect to DB, open connection, insert data, then close connection.
njtbConn = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Documents\Visual Studio 2010\WebSites\MyWeb\App_Data\TTdb.mdf;Integrated Security=True;User Instance=True")
njtbConn.Open()
njtbComm = New SqlCommand("SELECT * FROM UJE AS UserTable1", njtbConn)
njtbComm.ExecuteNonQuery()
njtbConn.Close()
njtbConn.Dispose()
You could use a select into {table name }from (select * from source) statement.
Then to get the user name you could use :
DECLARE @sys_usr char(30)
SET @sys_usr = SYSTEM_USER
Here is the reference for the select into: http://msdn.microsoft.com/en-us/library/ms188029.aspx
You will have to make this a dynamic sql using sp_executesql since you are concatenating the user name into the name of the table.