복붙노트

[SQL] 어떻게 열 이름 SqlDataReader.GetValue하여 데이터를 얻을 수 있습니다

SQL

어떻게 열 이름 SqlDataReader.GetValue하여 데이터를 얻을 수 있습니다

나는 DB에서 값을 읽어 SqlDataReader.GetValue 방법을 사용하십시오

Log.WriteLine("Value of CompanyName column:" + thisReader.GetValue(1)); 

GetValue 매개 변수로하는 컬럼의 인덱스를 얻을. 어떻게 열 이름 대신 인덱스를 지정할 수 있습니다?

해결법

  1. ==============================

    1.

    Log.WriteLine("Value of CompanyName column:" + thisReader["CompanyName"]); 
    
  2. ==============================

    2.또한이 작업을 수행 할 수 있습니다.

    또한이 작업을 수행 할 수 있습니다.

    //find the index of the CompanyName column
    int columnIndex = thisReader.GetOrdinal("CompanyName"); 
    //Get the value of the column. Will throw if the value is null.
    string companyName = thisReader.GetString(columnIndex);
    
  3. ==============================

    3.thisReader.GetString (INT columnIndex에)

    thisReader.GetString (INT columnIndex에)

  4. from https://stackoverflow.com/questions/8655965/how-to-get-data-by-sqldatareader-getvalue-by-column-name by cc-by-sa and MIT license