0

我在 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();
4

1 回答 1

-2

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

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

于 2013-03-27T12:45:52.180 回答