开发者

inserting DataTable into DB using DataAdapter does'nt work

开发者 https://www.devze.com 2023-02-22 13:53 出处:网络
I am trying to insert DataTable into a DB table (the DB is on a mobile device - Psion), using a DataAdapter. from some reason, it does not work - when i check the DB table - it simply appears as an em

I am trying to insert DataTable into a DB table (the DB is on a mobile device - Psion), using a DataAdapter. from some reason, it does not work - when i check the DB table - it simply appears as an empty table...

the co开发者_StackOverflowde: >

private void btnCommTables_Click(object sender, EventArgs e)

{

try

{

DataSet ds = WSDanielGroup.Instance._WSDanielGroupToDevice.GetLoadTables();

             DataTable DT = ds.Tables["Peer"];  

            string SelectCMD = "INSERT INTO Peer(ID,PeerID) Values(?,?)";  
            SqlCeConnection cn = new SqlCeConnection(DBManager.sLocalConnectionString);  





          SqlCeDataAdapter da=new SqlCeDataAdapter();  
            da.InsertCommand = new SqlCeCommand(SelectCMD, cn);  

            cn.Open();  

            da.InsertCommand.Parameters.Add("@ID", SqlDbType.Int,4,"ID");  

            da.InsertCommand.Parameters.Add("@PeerID", SqlDbType.NVarChar,50, "PeerID");  
            int numRows = da.Update(DT);         
 }  


One possible explanation is that your DataTable doesn't have the correct RowVersions. The DataAdapter will only update rows that have been changed in the table. If you get it from somewhere else, it thinks everything's OK and nothing needs to be updated (rows not marked "dirty"). More info here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号