I do not understand why I am getting this error. I have the exact statement used elsewhere accessing a differnt table with different field names of course and that one works.
These are the SQL fields:
Here is the code in the ...aspx.cs file
strUser is passed into the method
I just don't get why it get the following error:
Thanks for your input.
These are the SQL fields:
Code:
SELECT [user_id]
,[user_fname]
,[user_lname]
,[user_details]
,[user_created]
,[user_created_by]
,[user_modified]
,[user_modified_by]
FROM [uac].[dbo].[user]
Here is the code in the ...aspx.cs file
Code:
string sqlSecurity = ConfigurationManager.AppSettings["SQL_Security"];
string sqlDatasource = ConfigurationManager.AppSettings["SQL_Server"];
string sqlCatalog = ConfigurationManager.AppSettings["UAC_Catalog"];
string strUser = HttpContext.Current.User.Identity.Name.ToString().TrimStart().Replace("UFP\\", "").Trim();
SqlConnection con = new SqlConnection(sqlDatasource + sqlCatalog + sqlSecurity);
con.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO user (" +
"user_id,user_fname,user_lname,user_details,user_created,user_created_by)" +
" VALUES (@id, @fname, @lname, @details, @created, @createdby) SELECT user_id = SCOPE_IDENTITY()", con);
cmd.Parameters.Add("@id", SqlDbType.NChar, 20).Value = lbl_userId.Text.ToString().Trim();
cmd.Parameters.Add("@fname", SqlDbType.NChar, 50).Value = lbl_userFirstName.Text.ToString().Trim();
cmd.Parameters.Add("@lname", SqlDbType.NChar, 50).Value = lbl_userLastName.Text.ToString().Trim();
cmd.Parameters.Add("@details", SqlDbType.NChar, 100).Value = txt_userDetails.Text.Trim();
cmd.Parameters.Add("@created", SqlDbType.DateTime).Value = DateTime.Now;
cmd.Parameters.Add("@createdby", SqlDbType.NChar, 20).Value = strUser;
GetAuthorizedUserInfo(cmd.ExecuteScalar().ToString());
strUser is passed into the method
I just don't get why it get the following error:
Code:
Incorrect syntax near the keyword 'user'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'user'.
Thanks for your input.