Logon user name

sadesh kumar asked on May 29, 2014 08:57

I have added an user control page to store the data to the external database but the logon user name is not stored in the sql database column.I have used the following code: SqlCommand cm = new SqlCommand(" INSERT INTO jobpost ( postingid, companyid, companyname, jobid, jobtitle, industry, discipline,qualification, experience, jobtype, joblevel, jobterm, travel, city, country, jobdescription, noofapplicants, jobstatus, postedon,postedby ) VALUES ('fd','ff','df','" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "','" + TextBox9.Text + "','" + TextBox10.Text + "','" + TextBox11.Text + "','" + TextBox12.Text + "','" + TextBox13.Text + "','" + TextBox14.Text + "','" + TextBox15.Text + "','" + DateTime.Now.ToShortDateString() + "','" +CMSWebParts_Membership_Logon_currentuser.CacheItems.ToString()+ "')", cn);

Recent Answers


Richard Sustek answered on June 9, 2014 02:37

Hi,

Thank you for your message.

Can you please debug your code and check if all fields are correct? Is the query itself executing correctly?

Also this: CMSWebParts_Membership_Logon_currentuser.CacheItems.ToString() is definitely wrong. I'm guessing you want to get the user name of currently logged user, am I correct? If so it really depends which version you are using. In version 8 you can get the user name like this:

 MembershipContext.AuthenticatedUser.UserName

Kind regards,

Richard Sustek

0 votesVote for this answer Mark as a Correct answer

sadesh kumar answered on June 9, 2014 09:20

I am using Kentico CMS7 my source code is :SqlCommand cm = new SqlCommand(" INSERT INTO jobpost ( postingid, companyid, companyname, jobid, jobtitle, industry, discipline,qualification, experience, jobtype, joblevel, jobterm, travel, city, country, jobdescription, noofapplicants, jobstatus, postedon,postedby ) VALUES ('fd','ff','df','" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','" + TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "','" + TextBox9.Text + "','" + TextBox10.Text + "','" + TextBox11.Text + "','" + TextBox12.Text + "','" + TextBox13.Text + "','" + TextBox14.Text + "','" + TextBox15.Text + "','" + DateTime.Now.ToShortDateString() + "','" +CMS.CMSHelper.CMSContext.CurrentUser.UserName+ "')", cn);Its working correctly.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.