在向数据集添加新行时,应如何更新原始数据库 [英] How should I update original database upon addition of new row in to dataset

查看:75
本文介绍了在向数据集添加新行时,应如何更新原始数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone,



我使用以下代码将记录集(来自ADO)转换为ADO.net的数据集。我在数据集中只有一个表。



我正在尝试将新行添加到数据集中,然后更新原始数据库。我收到以下错误。



错误:

System.Data.OleDb.OleDbDataAdapter'无法转换为'System.Data.SqlClient .SqlDataAdapter





Hello Everyone,

I converted recordset( comes from ADO) to dataset of ADO.net using below code. I have just one table in dataset.

I am trying to add new row in to dataset and then update original database. I am getting below error.

Error:
System.Data.OleDb.OleDbDataAdapter' cannot be converted to 'System.Data.SqlClient.SqlDataAdapter


Dim da1 As New System.Data.OleDb.OleDbDataAdapter()
        Dim ds As New DataSet()

        da1.FillSchema(ds, SchemaType.Source, "Students")
        da1.Fill(ds, recStudents, "Students")




Dim dt As DataTable
        dt = ds.Tables(0)
        Dim dr As DataRow
        dr = dt.NewRow()







dr("RollNo") = 12
        dr("Name") = "Mike"




dt.Rows.Add(drCurrent)
        MsgBox("Add was successful.")
        Dim objCommandBuilder As New SqlCommandBuilder(da1) ' This line throws above error

       'Dim objCommandBuilder As New OleDb.OleDbCommandBuilder(da1) ' Alternatively tried this one- No error but original database was not updated.
        da1.Update(ds, "Students")
       
Questions:
a) Am I missing somthing?
b) Can I convert Recordset to Dataset and Once I have dataset, can I update original database?


Please help.

Regards,
Joy

推荐答案





请更新以下代码行。

Hi,

Please update the line line of code as below.
Dim objCommandBuilder As New SqlCommandBuilder(da1)






To

Dim objCommandBuilder As New OleDbCommandBuilder(da1)





希望你的问题能解决。



Hope your problem would solve.


这篇关于在向数据集添加新行时,应如何更新原始数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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