我在带有 vb.net 和 sql CE 3.5 的 wpf 中有以下代码,我的操作系统是 win7 64 位。Visual Studios 是 2010 年。我导入了以下内容:
Imports System.ComponentModel
Imports System.Data.SqlServerCe
Imports System.Data
代码的主要部分是:
Dim Con As SqlCeConnection = New SqlCeConnection(DataSource)
Dim Cmd As SqlCeCommand
If Con.State = ConnectionState.Closed Then Con.Open()
'Inserting Prime Details
Try
Cmd = New SqlCeCommand("INSERT INTO [ContactPrime]([ID],[Namee],[Company],[JobTitle],[Number],[Address],[Typee] VALUES (@ID,@Namee,@Company,@JobTitle,@Number,@Address,@Typee)", Con)
With InsertObject.Prime
Cmd.Parameters.Add(New SqlCeParameter("@ID", SqlDbType.NVarChar)).Value = .ID
Cmd.Parameters.Add(New SqlCeParameter("@Namee", SqlDbType.NVarChar)).Value = .Namee
Cmd.Parameters.Add(New SqlCeParameter("@Company", SqlDbType.NVarChar)).Value = .Company
Cmd.Parameters.Add(New SqlCeParameter("@JobTitle", SqlDbType.NVarChar)).Value = .JobTitle
Cmd.Parameters.Add(New SqlCeParameter("@Number", SqlDbType.NVarChar)).Value = .Number
Cmd.Parameters.Add(New SqlCeParameter("@Address", SqlDbType.NVarChar)).Value = .Address
Cmd.Parameters.Add(New SqlCeParameter("@Typee", SqlDbType.NVarChar)).Value = .Typee
End With
Cmd.ExecuteNonQuery()
Catch ex As Exception
End Try
'Inserting Numbers of Contact
Try
For Each num In InsertObject.Numbers
Cmd = New SqlCeCommand("INSERT INTO [ContactNumbers]([ContactID],[ID],[Title],[Mobile],[Land],[Fax],[Email],[IsPrimary] VALUES (@ContactID,@ID,@Title,@Mobile,@Land,@Fax,@Email,@IsPrimary)", Con)
With num
Cmd.Parameters.Add(New SqlCeParameter("@ContactID", SqlDbType.NVarChar)).Value = .ContactID
Cmd.Parameters.Add(New SqlCeParameter("@ID", SqlDbType.NVarChar)).Value = .ID
Cmd.Parameters.Add(New SqlCeParameter("@Title", SqlDbType.NVarChar)).Value = .Title
Cmd.Parameters.Add(New SqlCeParameter("@Mobile", SqlDbType.NVarChar)).Value = .Mobile
Cmd.Parameters.Add(New SqlCeParameter("@Land", SqlDbType.NVarChar)).Value = .Land
Cmd.Parameters.Add(New SqlCeParameter("@Fax", SqlDbType.NVarChar)).Value = .Fax
Cmd.Parameters.Add(New SqlCeParameter("@Email", SqlDbType.NVarChar)).Value = .Email
Cmd.Parameters.Add(New SqlCeParameter("@IsPrimary", SqlDbType.Bit)).Value = .IsPrimary
End With
Cmd.ExecuteNonQuery()
Next
Catch ex As Exception
End Try
我得到的错误是:
A first chance exception of type 'System.Data.SqlServerCe.SqlCeException' occurred in System.Data.SqlServerCe.dll
你能告诉我哪里做错了吗?连接工作得很好,我用一个 select 语句进行了测试,它工作了,看来我的 insert 语句是错误的。
先感谢您。