2
DataTable에서 값의 인덱스를 가져와야합니다.DataTable에서 값 인덱스 얻기
저는 그렇게하려고합니다.
SqlDataAdapter da = new SqlDataAdapter("SELECT MessageID,SenderID,MessageContent FROM Messages WHERE ThreadID="+ThreadID, connectionString);
//Get all messages in the Thread.
DataTable dt = new DataTable();
da.Fill(dt);
da.SelectCommand.CommandText = "SELECT MessageID,SenderID,MessageContent FROM Messages WHERE MessageID="+MessageID;
//Get the message which i need to get index.
DataTable dtMsg = new DataTable();
da.Fill(dtMsg);
//Get index of dtMsg.Rows[0] in dt.
int msgIndex = dt.Rows.IndexOf(dtMsg.Rows[0]);
디버깅 값은 동일하지만 항상 -1을 반환 할 때 분석했습니다. 내가 할 수있는 일은 무엇인가?
당신은 행이 데이터 테이블 dtMsg에 실제로 데이터 테이블 (DT)의 행을 찾고 있습니다
아니요. 두 번째 쿼리에서 첫 번째 쿼리의 모든 메시지를 가져 오지 않습니다. 하나의 메시지가 나타납니다. dt에 모든 메시지가 포함됩니다. 색인을 가져와야하는 행이 하나만있는 dtMsg. dtMsg가 아닌 dt를 찾으려고합니다. –
dtMsg에서 하나의 메시지가 있는데 dt에서 해당 메시지의 해당 색인을 찾아야합니다. 맞습니까? 그렇다면 dtMsg의 행에서 MessageID 값을 사용하여 dt를 찾거나 선택해야합니다. – LaughingJohn
답변을 추가 한 코드를 참조하십시오 .. – LaughingJohn