私は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();