无法在SQLCE中找到重复记录

无法在SQLCE中找到重复记录

本文介绍了无法在SQLCE中找到重复记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的名字是Anuar,我正在使用VB.net在移动扫描仪上开发扫描应用程序。

我在VB.net上很安静。我的程序将扫描PalletNo和RackNo并将其存储在数据库(SQLCE)上。对于每个重复的PalletNo,系统将通过消息警告用户。我已成功保存记录,但我无法查询特定记录进行检查..请参阅我的编码。请帮忙?



我的表是扫描(

Hi,
My name is Anuar, I am developing scanning application on mobile scanner using VB.net.
i''m quiet new with VB.net. My program will scan PalletNo and RackNo and store it on database (SQLCE). For every duplicate PalletNo, system will warn user with message. i have successfully save the record but i cant query specific record for checking.. refer to my coding. please help?

My Table is Scan (

PalletNo(nChar 10), RackNo(nChar 5)



)

Private Sub txtPallet_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPallet.KeyPress

        If e.KeyChar = Chr(13) Then
            Try
                'Check connection to network
                If Not Connected_To_Network() Then
                    MessageBox.Show("You are not connected to the network!", "No Connection")
                    Exit Sub
                End If
                'Create Connection to database Local
                cn = New SqlCeConnection("Data source = \Program files\SCANNER\appDatabase.sdf;persist security info= false")
                cn.Open()

                'check data exist or not
                cmd = New SqlCeCommand("Select * From Scan Where PalletNo ='" & txtPallet.Text & "'", cn)
                Rs = cmd.ExecuteResultSet(ResultSetOptions.Scrollable)
                Row = Rs.HasRows

                'Proceed
                If Row = False Then 'No data
                    'Proceed with saving the data..
                    Else
                        MsgBox("Invalid Pallet No.", MsgBoxStyle.Critical)
                        txtPallet.Text = ""
                        txtPallet.Focus()
                    End If
                End If

                cmd2.Dispose()
                DS.Dispose()

            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.Critical)
            End Try

        End If
    End Sub 



谢谢


Thank You

推荐答案

cmd = new SqlCeCommand("SELECT COUNT(PalletNo) FROM Scan WHERE PalletNo = @PN", cn)
cmd.Parameters.AddWithValue("@PN", txtPallet.Text)
If (cmd.ExecuteScalar = 0) Then
   ' Save your data
Else
   ' Report a problem
End If



这篇关于无法在SQLCE中找到重复记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 18:41