如何获得uniqueIntifier的UserId

时间:2013-03-27 12:32:07

标签: asp.net

我在asp.net网络表单中编码。我有默认情况下从asp.net生成的用户表 我需要获取当前UserId,在我的情况下默认情况下是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();

1 个答案:

答案 0 :(得分:-2)

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

此外,请参阅此前一个特定于返回GUID的答案:https://stackoverflow.com/a/8398174/280785