Tag: oledbdataadapter

使用OleDbDataAdapter更新DataTable C#

我一直在尝试使用OleDbDataAdapter来更新DataTable,但对这些命令感到困惑。 因为我有时从不同的表中获取信息,所以我不能使用CommandBuilder。 所以我试图在我的on上创建命令,但发现参数很难。 DataTable.GetChanges返回需要使用INSERT或UPDATE命令的行 – 我想我无法区分它们。 我需要你完成以下内容: DataTable dt = new DataTable(); OleDbDataAdapter da = new OleDbDataAdapter(); // Here I create the SELECT command and pass the connection. da.Fill(dt); // Here I make changes (INSERT/UPDATE) to the DataTable (by a DataGridView). da.UpdateCommand = new OleDbCommand(“UPDATE TABLE_NAME SET (COL1, COL2, …) VALUES (@newVal1, @newVal2, …) WHERE […]

使用OleDb写入excel

我试图将数据行从sql导出到excel但我的插入命令似乎每次都失败。 我花了很多时间试图创造这个,但我终于遇到了困难。 excel文档是由IRS生成的文档,我们不会大声修改第16行以上的任何内容。第16行是标题行,下面的所有内容都需要来自sql的数据。 标题名称都包含空格,这似乎是我遇到麻烦的地方。 从第16行开始,列名称为:参加者名字,参加者姓氏,参加者PTIN,计划编号,CE奖励计划,完成日期 这就是我试图写入excel的方式 private void GenerateReport() { FileInfo xlsFileInfo = new FileInfo(Server.MapPath(CE_REPORTS_PATH + CE_PTIN_TEMPLATE + EXTENSION)); string connectionString = String.Format(@”Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=’Excel 8.0;HDR=Yes'”, xlsFileInfo.FullName); //create connection OleDbConnection oleDBConnection = new OleDbConnection(connectionString); oleDBConnection.Open(); //create the adapter with the select to get OleDbDataAdapter adapter = new OleDbDataAdapter(“SELECT * FROM [Sheet1$A16:F16]”, oleDBConnection); // Create the […]