0
我在wpf與vb.net和sql CE 3.5中的以下代碼,我的操作系統是win7 64位。視覺工作室是2010年我進口下列:SQL CE插入聲明與Vb.net
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
能否請你告訴我我做錯了。該連接完美工作,我測試了一個選擇語句,它的工作,似乎我的插入語句是錯誤的。
預先感謝您。
哈哈哈,謝謝你的作品,似乎我需要很快去看眼科醫生。 – surpavan 2012-07-22 09:49:50