我只是想将这个旧代码 VB 2010 转换为我的编译器 vb2017,我收到此错误:BC30455 未为“Public Sub New(connStr As String)”第 29 行的参数“connStr”指定参数。我找不到如何解决这个编译错误。谢谢
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' First approach:
' Create a case sensitive database by using the SqlCeEngine
' constructor.
If File.Exists("Test.sdf") Then
File.Delete("Test.sdf")
End If
' 1033: specifies the English locale with collation
' SQL_Latin1_General_CP1_CI_AS
Dim connStr As String = "Data Source='Test.sdf'; LCID=1033; Case Sensitive = TRUE"
Dim engine As New SqlCeEngine(connStr)
engine.CreateDatabase()
engine.Dispose()
' Second approach:
' Create a case-sensitive database by using the LocalConnectionString
' property.
If File.Exists("Test.sdf") Then
File.Delete("Test.sdf")
End If
Dim engine2 As New SqlCeEngine
engine2.LocalConnectionString =
"Data Source='Test.sdf'; LCID=1033; Case Sensitive = TRUE"
' 1033: specifies the English locale with collation
' SQL_Latin1_General_CP1_CI_AS
engine2.CreateDatabase()
engine2.Dispose()
Dim conn As SqlCeConnection = Nothing
Try
conn = New SqlCeConnection(connStr)
conn.Open()
'Retrieve the connection string information -
' notice the 'Case Sensitive' value
Dim dbinfo As List(Of KeyValuePair(Of String, String)) = conn.GetDatabaseInfo
Console.WriteLine(ChrW(10) & "GetDatabaseInfo() results:")
Dim kvp As KeyValuePair(Of String, String)
For Each kvp In dbinfo
Console.WriteLine(kvp)
Next
Catch ex As Exception
Console.WriteLine(ex.Message)
Finally
conn.Close()
Console.WriteLine(vbNewLine & vbNewLine & vbNewLine & "Press any key to continue...")
Console.Read()
End Try
End Sub
End Class
我希望在创建新数据库之前删除数据库(如果存在)。
您使用
engine
参数创建 connStr
:
Dim engine As New SqlCeEngine(connStr)
如果你想解决这个编译错误,你可以用同样的方式创建
engine2
:
Dim engine2 As New SqlCeEngine(connStr)