日期:2014-05-18  浏览次数:20717 次

如何取出datagridview的值然后插入到access
如题

------解决方案--------------------
(dataTable)dataGridview.dataSource,然后把dataTable的数据一行一行的insert也行,或直接通过dataTable.update()也行~
------解决方案--------------------
//导出数据到Excel
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

this.DataGridView1.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();

------解决方案--------------------
我用的是DataGrid测试过的,不知道楼主是不是这个要求。
------解决方案--------------------
VB.NET code
 Dim zd1 As String, zd2 As String, zd3 As String, zd4 As String, zd5 As String, zd6 As String
        For s = 0 To myDataset1.Tables(0).Rows.Count - 1
            zd1 = myDataset1.Tables(0).Rows(s).Item("字段1") & ""
            zd2 = myDataset1.Tables(0).Rows(s).Item("字段2") & ""
            zd3 = myDataset1.Tables(0).Rows(s).Item("字段3") & ""
            zd4 = myDataset1.Tables(0).Rows(s).Item("字段4") & ""
            zd5 = myDataset1.Tables(0).Rows(s).Item("字段5") & ""
            zd6 = myDataset1.Tables(0).Rows(s).Item("字段6") & ""

            sql = "INSERT INTO table(字段1,字段2,字段3,字段4,字段5,字段6) VALUES('" & zd1 & "','" & zd2 & "', '" & zd3 & "','" & zd4 & "','" & zd5 & "','" & zd6 & "')"
            MyCommand = New OleDbCommand(sql, cn)
            MyCommand.ExecuteNonQuery()
        Next

------解决方案--------------------
string sql = "insert into 成绩 (成绩表字段1,成绩表字段2)values(@xuhao,@name)";
------解决方案--------------------
插入语句中没有表的字段
改为:
string sql = "insert into 成绩 (成绩表字段1,成绩表字段2)values(@xuhao,@name)";