2013-03-27 1 views
0

나는 asp.net 웹 폼으로 코딩하고있다. 나는 사용자와 테이블이 기본 내가 현재의 사용자 아이디를 얻을 필요가 에 의해 asp.net에서 발생 가지고있는 기본적으로 내 경우uniqueidentifier 인 UserId를 얻는 방법

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(); 
+2

이 게시물은 질문에 대한 답변을 제공합니까? http://stackoverflow.com/questions/4769313/getting-the-guid-of-the-current-user – Netricity

답변

-2

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

을 시도, 특정이 이전 답변을 참조 고유 식별자입니다 GUID를 반환하는 방법 : https://stackoverflow.com/a/8398174/280785

+2

왜 'SELECT CAST (scope_identity() AS int)'를 사용하고 있습니까? 유니크 식별자가 사용 중임을 나타내는 질문이 –

+0

executenonquery를 통해 캐스트 또는 무언가로 uniqueidentifier를 얻을 수 없습니다. 그냥 위쪽 선택 쿼리를 사용 ... – Kadir

관련 문제