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里的值怎么循环添加到语句中啊?????????
{
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里的值怎么循环添加到语句中啊?????????
希望大家给点意见!!!
你这个想法就错误,即时你的DataTable是自己打造的,也可以使用DataAdapter的Update方法
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;
}
就是,直接用sqlServer的导入导出功能即可,既简单又省事
InsertCommand.CommandText="Insert into a(fd ) values(@fd)";
UpdateCommand.CommandText="Insert into a(fd) values(@fd)";
.......