vb.net – 从数据库中删除时,SQL逻辑错误或缺少数据库没有此类表

vb.net – 从数据库中删除时,SQL逻辑错误或缺少数据库没有此类表,第1张

概述我的联系: Public con As SQLiteConnection = New SQLiteConnection("Data Source=trancebeats.s3db") 并在表单加载时打开连接 插入新值: Public Sub InsertNewCatSub() prUpdate.Value = 0 prUpdate.Maximum = 1 我的联系:

Public con As sqliteConnection = New sqliteConnection("Data Source=trancebeats.s3db")

并在表单加载时打开连接

插入新值:

Public Sub InsertNewCatSub()        prUpdate.Value = 0        prUpdate.Maximum = 1        lblUpdateResults.Text = prUpdate.Value & " of " & prUpdate.Maximum & " Checked"        lblUpdateResults.Forecolor = color.Red        TotUpd = 0        TotNew = 0        Dim filename1 = Path.GetfilenameWithoutExtension(NewCat)        Dim filename2 = filename1.Replace("[","")        Dim filename3 = filename2.Replace("]","")        Dim filename4 = Path.GetDirectoryname(NewCat)        If con.State = ConnectionState.Closed Then            con.open()        End If        Dim querytxt As String = "Select * from trancebeats Where Cat = '" & filename3 & "' Group By Cat"        Dim Adp As sqliteDataAdapter = New sqliteDataAdapter        Dim Cmd As sqliteCommand = New sqliteCommand        Dim tableNewCat As New Datatable        tableNewCat.Rows.Clear()        Dim i As Integer        With Cmd            .CommandText = querytxt            .Connection = con        End With        With Adp            .SelectCommand = Cmd            .Fill(tableNewCat)        End With        If tableNewCat.Rows.Count > 0 Then            For i = 0 To tableNewCat.Rows.Count - 1                If filename3 = tableNewCat.Rows(i)("Cat") Then                    MsgBox("Cat. Already Exists!!!")                Else                    GoTo write_new_cat                End If            Next        Elsewrite_new_cat:            Try                Dim file As String = NewCat                Dim filepath As String = file.Substring(0,file.LastIndexOf("\"))                Dim lines As New List(Of String)                lines.AddRange(System.IO.file.ReadAlllines(NewCat))                For co As Integer = 0 To lines.Count - 1                    If lines(co).Length > 0 Then                        Try                            Dim a1() As String = lines(co).Split("|")                            Dim Cat As String = a1(0)                            Dim Title As String = a1(1)                            Dim Artist As String = a1(2)                            Dim Album As String = a1(3)                            Dim Year As String = a1(4)                            Dim Genre As String = a1(5)                            Dim Publisher As String = a1(6)                            Dim Site As String = a1(7)                            Dim MP3file As String = filepath & "\" & a1(8)                            Dim Cover As String = filepath & "\[" & Cat & "].jpg"                            Dim CmDWrtN As sqliteCommand = New sqliteCommand                            With CmDWrtN                                .CommandText = "Insert Into trancebeats Values('" _                                & Cat & "','" & Title & "','" & Artist & "','" & Album & "'," & Year & ",'" & Genre & "','" & Publisher & "','" & Site & "','" & filepath.Replace("'","''") & "','" & Cover.Replace("'",'" & MP3file.Replace("'","''") & "')"                                .Connection = con                                .ExecuteScalar()                            End With                        Catch ex As Exception                            MsgBox(ex.Message & NewCat)                        End Try                    End If                Next                TotNew += 1            Catch ex As Exception                MessageBox.Show(ex.ToString,"Error Reading file " & NewCat)            End Try            btnClear.Enabled = True        End If        con.Close()        prUpdate.Value += 1        lblUpdateResults.Text = prUpdate.Value & " of " & prUpdate.Maximum & " Checked"    End Sub

从数据库删除所有内容

Private Sub btnClear_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles btnClear.Click    If con.State = ConnectionState.Closed Then        con.open()    End If    Dim querytxt As String = "Delete from trancebeats"    Dim Cmd As sqliteCommand = New sqliteCommand    Try        With Cmd            .CommandText = querytxt            .Connection = con            .ExecuteScalar()            MsgBox("Data Cleared")            Dim pn As Panel            pn = Me.Controls.Item("pnNew")            Me.Controls.Remove(pn)            flResults.Controls.Clear()            btnClear.Enabled = False        End With    Catch ex As Exception        MsgBox(ex.Message)    End TryEnd Sub

当我清除数据库
我从文件中插入一个新行
然后当我尝试清除数据库时
它给了我一个错误:

sql逻辑错误或缺少数据库没有这样的表:trancebeats

解决方法 不确定这是否会对你有所帮助,但我遇到了类似的问题:
‘没有这样的表:***’

在我的情况下,事实证明我的连接字符串将数据库指定为相对路径:

'URI=file: mydatabase.sqlite'

一切正常,直到我在我的应用程序中使用’OpenfileDialog’.这会更改当前目录,并抛出连接字符串.快速修复,在连接字符串中使用数据库的绝对路径:

'URI=file: C:\Test\mydatabase.sqlite'
总结

以上是内存溢出为你收集整理的vb.net – 从数据库中删除时,SQL逻辑错误或缺少数据库没有此类表全部内容,希望文章能够帮你解决vb.net – 从数据库中删除时,SQL逻辑错误或缺少数据库没有此类表所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1242116.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存