sql-server - 如何将一行与 Visual Basic 中的特定 SQL 列相关联?
问题描述
我正在用 Visual Basic 模拟 ATM。我在 SQL 中有一个名为 Authentication 的表。该表包含两列:NUM_CARD 列和 PIN_CARD 列。在插入卡 ID 时,我需要将行 (0) 列 1、行 (1) 列 (1)、行 (2) 列 (1) 等与其他行进行匹配。我怎样才能做到这一点?提前致谢。
DBConnection 类如下:
Imports System
Imports System.Data.Sql
Imports System.Data.SqlClient
Public Class clsDBConnection
'Class variables'
Public cn As SqlConnection
Public cmd As SqlCommand
Public dr As SqlDataReader
'Constructor of the Connection class that creates the connection'
Sub New()
Try
cn = New SqlConnection("Data Source=JOVALLES-PC\SQLSERVEREX;Initial Catalog=SigmasBank;Integrated Security=True")
cn.Open()
Catch ex As Exception
MsgBox("Error connecting due to:: " + ex.ToString)
End Try
End Sub
'Returns true or false if the record exists or not in the database'
Function validationAutentication_p1(ByVal NUM_CARD As String) As Boolean
Dim result As Boolean = False
Try
cmd = New SqlCommand("Select * from Autentication where NUM_CARD='" & NUM_CARD & "'", cn)
dr = cmd.ExecuteReader
If dr.HasRows Then
result = True
End If
dr.Close()
Catch ex As Exception
MsgBox("Error in the procedure: " + ex.ToString)
End Try
Return result
End Function
Function validationAutentication_p2(ByVal PIN_CARD As String) As Boolean
Dim result As Boolean = False
Try
cmd = New SqlCommand("Select * from Autentication where PIN_CARD='" & PIN_CARD & "'", cn)
dr = cmd.ExecuteReader
If dr.HasRows Then
result = True
End If
dr.Close()
Catch ex As Exception
MsgBox("Error in the procedure: " + ex.ToString)
End Try
Return result
End Function
End Class
插入卡 ID 表格:
Public Class FRM_InsertCardID
Public conn As New clsDBConnection
Private Sub BTN_Ok_Click(sender As Object, e As EventArgs) Handles BTN_Ok.Click
If TXB_CardID.Text.Length = 0 Then
MsgBox("Please fill in field.")
ElseIf TXB_CardID.Text.Length > 0 And TXB_CardID.Text.Length < 16 Then
MsgBox("Your Card ID must be 16 digits.")
ElseIf conn.validationAutentication_p1(TXB_CardID.Text) = False Then
MsgBox("The Card ID doesn't exist.")
Else
FRM_PIN.Show()
Me.Hide()
TXB_CardID.Text = ""
End If
End Sub
插入 PIN 表单:
Public Class FRM_PIN
Public conn As New clsDBConnection
Private Sub BTN_Ok_Click(sender As Object, e As EventArgs) Handles BTN_Ok.Click
If TXB_PIN.Text.Length = 0 Then
MsgBox("Please fill in field.")
ElseIf TXB_PIN.Text.Length > 0 And TXB_PIN.Text.Length < 4 Then
MsgBox("Your PIN must be 4 digits.")
ElseIf conn.validationAutentication_p2(TXB_PIN.Text) = False Then
MsgBox("Incorrect PIN Please try again.")
Else
FRM_Transaction.Show()
Me.Hide()
TXB_PIN.Text = ""
End If
End Sub
解决方案
不知道错字是否会导致问题?- - 验证
"我在 SQL 中有一个名为 Authentication 的表。" " cmd = New SqlCommand("Select * from Autentication where PIN_CARD='" & PIN_CARD & "'", cn)"
推荐阅读
- reactjs - 如果想在我的整个 React 应用程序中访问变量,我应该在哪里设置变量?
- haskell - 从字符串列表中删除特殊字符 Haskell
- javascript - Chart.js - 图表响应/调整大小
- c++ - 如何修复并使我的代码在 C++ 中工作?
- javascript - Cocos Creator - 碰撞不适用于从 JS 添加的节点
- c++ - weak_ptr 中的可能错误已传递给线程
- asp.net-mvc - ASP.NET MVC:使用 Microsoft.AspNet.Identity.Owin 会导致错误“对象引用未设置为对象的实例”。
- r - 使用自定义主题将图例添加到 ggplot 折线图的问题
- react-native - 是否有适合 @hmscore/react-native-hms-map 中所有可用标记的函数
- go - 你如何读取每 N 位?