0

I am coding in asp.net web forms . I have table with users generated from asp.net by default I need to get current UserId which in my case by default is uniqueidentifier

string user = User.Identity.Name; //this give me the name
            string name = TextBoxCategoryName.Text;
            this.connection.Open();
            command = connection.CreateCommand();
            command.CommandText = "insert into ProfitCategories(name, IdUser/*this is foreign key to Users table*/) values ( '" + name + "', '"+user+"' )";
            command.ExecuteNonQuery();

            connection.Close();
Krasimir
  • 259
  • 4
  • 9
  • 28
  • 2
    Does this post answer your question? http://stackoverflow.com/questions/4769313/getting-the-guid-of-the-current-user – Netricity Mar 27 '13 at 12:45

1 Answers1

-2

Try ExecuteScalar() http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx

Also, see this previous answer specific to returning a GUID: https://stackoverflow.com/a/8398174/280785

Community
  • 1
  • 1
s15199d
  • 7,261
  • 11
  • 43
  • 70
  • 2
    Why are you using `SELECT CAST(scope_identity() AS int)`? The question states that a uniqueidentifier is being used – Jack Pettinger Mar 27 '13 at 13:34
  • You can't get uniqueidentifier with cast or something via executenonquery. just use upper select query ... – Kadir Mar 27 '13 at 14:45