0

私はasp.net Webフォームでコーディングしています。デフォルトで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 に答える