VB.net和SQLite-将数据写入db的最佳方法 [英] VB.net and SQLite - Best way to write data to db

查看:988
本文介绍了VB.net和SQLite-将数据写入db的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对VB.net和SQLite还是很陌生...我有一个子例程,可使用数据适配器和数据集将数据写入db.

这整个下面的子工作正常.如此简单的任务看起来非常耗时.我可能要执行1000次,每次必须创建一个新的数据集dataadapter,填充它并进行更新.

我做得太多吗?
有更好的方法来更新数据库吗?或者这是正常的吗?

感谢您提供的任何建议



Im fairly new to VB.net and SQLite...I have a subroutine which writes data to a db using data adapters and datasets.

This whole sub below works fine. It just looks very long and time consuming for such a simple task. I might want to do this 1000''s of times and each time I have to create a new dataset, dataadapter , fill it and do the updates.

Am I doing too much?
Is there a better way to update a db or is this normal?

Thanks for any advice you can provide
Al


Public Shared Sub SaveSumm(ByVal TestNo As Integer, ByVal Valx As Integer)

    Dim Tab1 As String = "USummary"
    Dim Conn1 As New SQLiteConnection(ConnMySys)

        Dim z As String = Trim(TestNo.ToString)
        Dim strSQL As String = "SELECT * FROM " & Tab1 & " WHERE SumTestNo ='" & z & "'"

        Dim da As New SQLiteDataAdapter(strSQL, Conn1)
        Dim ds1 As New DataSet(Tab1)
        da.FillSchema(ds1, SchemaType.Source, Tab1)
        da.Fill(ds1, Tab1)
        da.AcceptChangesDuringFill = False

        Dim foundRows() As DataRow
        foundRows = ds1.Tables(Tab1).Select("SumTestNo = " & z)
        Dim cb As New SQLiteCommandBuilder(da)  'needed

        If foundRows.Count = 0 Then
            'add new row
            Dim dsNewRow As DataRow
            dsNewRow = ds1.Tables(Tab1).NewRow()
            dsNewRow.SetField("SummTestNo", TestNo)
            dsNewRow.SetField("SummCount1", Valx)
            dsNewRow.SetField("SummTested", True)
            dsNewRow.SetField("SummImpScore", GetTestImpScore(TestNo))
            ds1.Tables(Tab1).Rows.Add(dsNewRow)
        Else
            'update old row even if its already the same
            foundRows(0).SetField("SummTestNo", TestNo)
            foundRows(0).SetField("SummCount1", Valx)
            foundRows(0).SetField("SummTested", True)
            foundRows(0).SetField("SummImpScore", GetTestImpScore(TestNo))
        End If
        da.Update(ds1, Tab1)   'used by both

end sub

推荐答案

我不确定您真正想要实现什么...

请从这里开始: http://www.dreamincode.net/forums/topic/157830-using-sqlite-with-c%23/ [在C#应用程序中使用SQLite [ ^ ]
有关SQLite的更多信息,请参见: http://www.sqlite.org/ [
I''m not sure what you really want to achieve...

Please, start here: http://www.dreamincode.net/forums/topic/157830-using-sqlite-with-c%23/[^]
Then read this article on CP: Using SQLite in your C# Application[^]
More about SQLite you''ll find at: http://www.sqlite.org/[^]


使用INSERT INTO查询可在由DataAdapters插入的数据表中插入单行

访问此链接以了解有关INSERT INTO语法的更多信息

单击此处
Use INSERT INTO Query to insert single row in datatable insted of DataAdapters

Visit This Link to know more on INSERT INTO Syntax

Click Here


这篇关于VB.net和SQLite-将数据写入db的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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