我在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();
答案 0 :(得分:-2)
尝试ExecuteScalar()http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executescalar.aspx
此外,请参阅此前一个特定于返回GUID的答案:https://stackoverflow.com/a/8398174/280785