2012-12-05 2 views
0

Visual Studio 2010 Express에서 여러 테이블과 관계가있는 SQL Compact Database (sdf-File)를 만들었습니다. 이 데이터베이스에서 강력하게 형식화 된 데이터 집합을 생성했습니다.로컬 Sql 압축 데이터베이스에서 강력한 형식의 데이터 집합을 업데이트하십시오.

이제 데이터베이스의 내용으로 데이터 세트를 채 웁니다. 그래서 다음 코드를 사용하여 데이터베이스에 연결하고 데이터 집합을 채 웁니다.

//My strongly typed dataset 
localData = new LokalStorageDataSet(); 

//SqlCe-Connection 
localConnection = new SqlCeConnection(@"Data Source=|DataDirectory|\TempStorage.sdf; Password='xyc';Persist Security Info=True"); 

localConnection.Open(); 
SqlCeCommand command = new SqlCeCommand("SELECT * FROM progstates", localConnection); 
localDataAdapter = new SqlCeDataAdapter(command); 

localDataAdapter.Fill(localData); 

문제는 데이터베이스에 행이 있지만 내 데이터 집합에 행이 추가되지 않는다는 것입니다.

SqlCeDataReader dr = command.ExecuteReader(); 

     while (dr.Read()) 
     { 
      ... 
     } 

당신이 나에게 내 데이터 세트는 데이터 집합의 테이블에서 행을하지 않는 이유를 줄 수 : 나는 SqlCeCommand의 결과를 읽기 위해 SqlCeReader를 사용하는 경우, 독자는 행을 반환?

편집 : 내 데이터 세트에서 새로운 데이터 테이블이 내가 요청한 일 (progstate)와 같은 동일한 열이 '표'라는 이름뿐만 아니라이 데이터 테이블은 0

답변

1
EDITED ***** 

Try This :- 

//My strongly typed dataset 
localData = new LokalStorageDataSet(); 

//SqlCe-Connection 
localConnection = new SqlCeConnection(@"Data Source=|DataDirectory|\TempStorage.sdf; Password='xyc';Persist Security Info=True"); 


SqlCeCommand command = new SqlCeCommand("SELECT * FROM progstates", localConnection); 

localConnection.Open(); 

var dataReader = command.ExecuteReader(); 

localData.Load(dataReader,LoadOption.Upsert,localData.Tables[0]); 

localConnection.Close(); 

의 행 개수를 가지고 생성 된 것을보고 또는 다음과 같이 DataAdapter를 사용하여이 작업을 수행 할 수 없습니다. -

localDataAdapter = new SqlCeDataAdapter(); 

SqlCeCommand command = new SqlCeCommand("SELECT * FROM progstates", localConnection); 

localDataAdapter.SelectCommand = command; 

localConnection.Open(); 

localDataAdapter.SelectCommand.ExecuteNonQuery(); 
localDataAdapter.Fill(localData.Tables[0]); 

localConnection.Close(); 
+0

감사합니다. 하지만 SqlCeDataAdapter와 함께 작동하지 않는 이유는 무엇입니까? 어댑터를 사용할 수 있으면 좋을 것입니다. 또한 데이터 집합의 데이터를 데이터베이스에 다시 쓸 때도 사용해야합니다 (dataAdapter.Update (dataset);)). 불행히도 이것은 작동하지 않습니다. : – Mossos

+0

너무 짧게 업데이트 해 드리겠습니다. – Derek

+0

데이터 집합 클래스에서 적절한 메서드를 찾을 수 없습니다. – Mossos

관련 문제