【问题标题】:Code Stopping when Opening an Oledbconnection打开 Oledb 连接时代码停止
【发布时间】:2015-03-14 04:38:49
【问题描述】:

运行以下代码,我的程序将无法通过此子程序中的“connection.Open()”行。在不需要数据读取器的情况下,我在使用数据读取器之前遇到了类似的问题,但是在这个子程序中,我没有做任何类似的事情,只是打开了与数据库的连接。我无法弄清楚我在这里做错了什么,特别是因为没有错误或任何东西。

Using connection As New OleDbConnection(connectionstring)
    connection.Open()

    Dim Command As New OleDbCommand("SELECT SUM(Price) FROM ItemsSold", conection)
    Dim Command2 As New OleDbCommand("SELECT SUM(TotalCost) FROM Inventory", connection)
    Dim Turnover As Double = Convert.ToDouble(Command.ExecuteScalar())
    Dim Cost As Double = Convert.ToDouble(Command2.ExecuteScalar())

    lblProfit.Text = "Profit: £" & (Turnover - Cost)

    connection.Close()
End Using

【问题讨论】:

  • 一定有错误——你说它坏了。使用 Try/Catch 获取结果。
  • 使用 Try/Catch 时出现错误“'System.Transactions.Diagnostics.DiagnosticTrace' 的类型初始化程序引发异常”你能告诉我这意味着什么吗?

标签: vb.net database-connection connection-string oledb


【解决方案1】:

啊,我用一个新的替换了 app.config 文件,程序现在再次完美运行。感谢您的帮助!

【讨论】:

    猜你喜欢
    • 2015-09-07
    • 1970-01-01
    • 1970-01-01
    • 2019-06-11
    • 2018-08-05
    • 1970-01-01
    • 2019-12-27
    • 1970-01-01
    • 2014-07-31
    相关资源
    最近更新 更多