如何从记录集写入数据网格视图? [英] How to write to a datagridview from a recordset?

查看:22
本文介绍了如何从记录集写入数据网格视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 SQL 数据库检索记录集.你有什么理由可以看出这行不通吗?dataFN 是 datagridview 中的名称,这是正确的.消息框显示大约 51,000 条记录,因此 SQL 命令运行良好.

Working with SQL database retrieving into a record set. Any reason you can see that this would not work? The dataFN is the name in the datagridview and this is correct. The messagebox shows 51,000 or so records, so the SQL command is working nicely.

提前致谢

       Dim i As Integer = 0
    rs.Open("SELECT Elig.FirstName, Elig.LastName, Elig.GroupID, CallLog.EligID, " + _
         "CallLog.DateTime, CallLog.AssignTo, CallLog.Status, CallLog.ReasonCode, " + _
         "CallLog.ReasonDesc FROM Elig INNER JOIN CallLog ON Elig.EligID = CallLog.EligID " + _
         "ORDER BY Elig.FirstName", AdoCon, rs.CursorType, rs.LockType, 0)

    MessageBox.Show("you have " + rs.RecordCount.ToString + " rows")

    While Not rs.EOF
        DataGridView1.Rows(i).Cells("DataFN").Value = rs.Fields("FirstName").Value.ToString
        rs.MoveNext()
        i += 1
    End While

推荐答案

您可以使用 OleDbDataAdapter 从记录集中填充数据集:

You can use an OleDbDataAdapter to fill a dataset from a recordset:

Using da as OleDbDataAdapter = New OleDbDataAdapter()
  Dim ds as DataSet = New Dataset
  da.Fill(ds, rs, tableName)
End Using

这将创建一个具有正确模式和数据的数据集——请注意,记录集已关闭(据我所知是不可逆的),因此,如果您要将数据写回数据库,则必须自己编写插入/更新/删除命令.

This will create a dataset with the correct schema and data -- note that the recordset is closed (irreversible as far as i have been able to discover), so if your going to write the data back to the DB, you'll have to make your own insert/update/delete commands.

我只建议将此作为使用 ADO.NET 的过渡步骤,但它确实可以在您进行升级时为您提供一个可行的应用程序.

I only recommend this as an interim step on the way to using ADO.NET, but it does work to give you a workable app while you work on upgrades.

这篇关于如何从记录集写入数据网格视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆