for (int q = 0; q < ds.Tables["计算机管理"].Rows.Count;q++ )
                    {
                        for (int a = 0; a < ds.Tables["计算机管理"].Columns.Count; a++)
                        {
                           
                               ds.Tables["计算机管理"].Rows[q][a].ToString;
                                                      }
                            
                           
                        }
                        
                    }
我可以从dataset中取出datatable表中的每一个字段...现在的想法是要插入到SQL表中.SQL表中已经有了相同结构的表.
但是这个insert语句十分不好控制,因为values(这里面的值要和SQL表中的列数相等)不然就插不进去.但是我一次只能取一个字段的值,该如何写这个代码啊!!!!!!!!!!!!!!!!!!!!! insert into aa values('"+ds.Tables["计算机管理"].Rows[q][a].ToString+"')------values里的值怎么循环添加到语句中啊?????????

解决方案 »

  1.   

    不能用dataadpater!!!因为我的datatable是一张独立的.不是从数据库里fill的.所以update()方法我放弃了。
    希望大家给点意见!!!
      

  2.   

    你没有完全理解dataadpater
      

  3.   


    你这个想法就错误,即时你的DataTable是自己打造的,也可以使用DataAdapter的Update方法
      

  4.   

    直接用sql语句,select  columnName1,columnName2.... into table2 from table1
      

  5.   

    这有什么难的吗?
    string a ="insert into aa values('";
    string b;
    StringBuilder temp=new StringBuilder;
    for (int q = 0; q < ds.Tables["计算机管理"].Rows.Count;q++ ) 
                        { 
                            for (int a = 0; a < ds.Tables["计算机管理"].Columns.Count; a++) 
                            { 
                               temp.append(",");  
                               temp.append(ds.Tables["计算机管理"].Rows[q][a].ToString); 
                            } 
                            temp.remove(0.1);                         
                            b=a+temp.tostring+"')";
                            使用查询字符串b执行数据库的插入命令;
                            temp.Length=0; 
                        } 
                         
      

  6.   


    就是,直接用sqlServer的导入导出功能即可,既简单又省事
      

  7.   

    自己写更新语句不就行了:
    InsertCommand.CommandText="Insert into a(fd ) values(@fd)";
    UpdateCommand.CommandText="Insert into a(fd) values(@fd)";
    .......