private bool LoadRecs(DataTable tbl) { // this function inserts the records into the respective tables in the local db bool blnUploaded = false; if (tbl.Rows.Count == 0) return (blnUploaded); SqlCeDataAdapter daCe = new SqlCeDataAdapter("select * from " + tbl + " ", strCEConnection); DataSet dsCe = new DataSet(); daCe.FillSchema(dsCe, SchemaType.Mapped, tbl.TableName); DataRow dr; for (int i = 0; i < tbl.Rows.Count; i++) { dr = dsCe.Tables[tbl.TableName].NewRow(); for (int k = 0; k < tbl.Columns.Count; k++) { try { dr[k] = tbl.Rows[i].ItemArray.GetValue(k).ToString().Trim(); } catch { dr[k] = System.DBNull.Value; } } dsCe.Tables[tbl.TableName].Rows.Add(dr); } SqlCeCommandBuilder cb = new SqlCeCommandBuilder(daCe); //seems this is needed to force the insert command to be assigned. daCe.InsertCommand = cb.GetInsertCommand(); try { //call update to move all the data from sampletable DataTable into the database table daCe.Update(dsCe, tbl.TableName); daCe.Dispose(); blnUploaded = true; } catch { blnUploaded = false; MessageBox.Show("Error"); } return (blnUploaded); } }
SET IDENTITY_INSERT " + tableName + " ON
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)