我使用以下代码使用名为db.sdf的SQlServer CE创建了一个数据库。
Dim connStr As String = "Data Source =\temp\emp.sdf;"
Try
'creating database
Dim engine As SqlCeEngine
engine = New SqlCeEngine(connStr)
engine.CreateDatabase()
engine.Dispose()
'creating table
Dim cn As New SqlCeConnection(connStr)
Dim sql As String
sql = "CREATE TABLE login "
sql &= "("
sql &= " username nvarchar(20) PRIMARY KEY,"
sql &= " password nvarchar(20)"
sql &= ")"
Dim cmd As New SqlCeCommand(sql, cn)
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
cmd.Dispose()
cn.Dispose()
MessageBox.Show("Succesfully created")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
但是我不知道它保存这个emp.sdf文件的位置以及如何查看它。我今天刚刚开始研究VB.NET Pocket PC应用程序,我很困惑,因为我的VB.NET连接代码与Pocket PC应用程序不兼容所以请帮我解决这个问题。请任何可以帮助我的教程。 感谢
答案 0 :(得分:1)
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim connetionString As String
Dim cnn As SqlConnection
connetionString = "Data Source=database server name;Initial Catalog=database name"
cnn = New SqlConnection(connection string)
Try
cnn.Open()
MsgBox("Connection Open ! ")
cnn.Close()
Catch ex As Exception
MsgBox("Can not open connection ! ")
End Try
End Sub
End Class
答案 1 :(得分:0)
创建数据库时,您已在连接字符串中提供了数据库名称...
Dim connStr As String = "Data Source =\temp\emp.sdf;"
...所以你应该在\ My Device下面找到一个\ temp文件夹,里面有emp.sdf文件。