Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在另一个datatable中的指定索引处插入datatable行?_C#_Datatable - Fatal编程技术网

C# 如何在另一个datatable中的指定索引处插入datatable行?

C# 如何在另一个datatable中的指定索引处插入datatable行?,c#,datatable,C#,Datatable,我有两个数据表,其中包含自动生成的列和来自两个不同Access数据库的信息 名单如下: 导出数据表(源) 学校数据表(目标) 我想选择导出数据库从第19列开始的信息(假设0=索引),并将该信息从第203列开始插入学校数据表(假设0=索引) 我已经尝试过这种方法: try { cb = new OleDbCommandBuilder(dataAdapterSchool); cb.GetUpdateComman

我有两个数据表,其中包含自动生成的列和来自两个不同Access数据库的信息

名单如下: 导出数据表(源) 学校数据表(目标)

我想选择导出数据库从第19列开始的信息(假设0=索引),并将该信息从第203列开始插入学校数据表(假设0=索引)

我已经尝试过这种方法:

 try
            {
                cb = new OleDbCommandBuilder(dataAdapterSchool);
                cb.GetUpdateCommand();
                cb.GetInsertCommand();
                cb.GetDeleteCommand();
                for (int i = 0; i <= 19; i++)
                {
                    DataRow newRow = schoolDb.NewRow();
                    newRow[i + 19] = exportDb.Columns[202 + i];                  
                }
                
                Grid.ItemsSource = schoolDb.DefaultView;
                dataAdapterSchool.Update(schoolDb);
                testbox.Text = cb.GetUpdateCommand().CommandText;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
试试看
{
cb=新的OleDbCommandBuilder(dataAdapterSchool);
cb.GetUpdateCommand();
cb.GetInsertCommand();
cb.GetDeleteCommand();

对于(int i=0;i您的代码中有一个错误:

for (int i = 0; i <= 19; i++)
{
    DataRow newRow = schoolDb.NewRow();
    newRow[i + 19] = exportDb.Columns[202 + i]
}

for(inti=0;谢谢,但是x在exportDb.Rows[x][202+i]中代表什么?在exportDb.row上迭代需要执行的for循环变量我尝试了您所说的,但我得到的错误是转换错误。我认为我在代码中犯了一个错误,但我找不到它。我这样做:```DataRow newRow=schoolDb.newRow();for(int i=0;i使用foreach迭代数据行项目时,可以这样做:
foreach(exportDb.Rows中的数据行){newRow[19+i]=row[202+i];}}
或者这样:
for(int x=0;i
嘿!我刚刚试过,但效果很好。我对解决这个问题的想法完全错误。谢谢你的帮助!