从VB.net输入到Access数据库的编号 [英] Number input from VB.net to an Access database
问题描述
嘿那里,
目前正在学习VB.net,作为今年的最终项目,我被要求做一个酒店预订系统。
Currently learning VB.net and as final project for this year I have been asked to make a hotel booking system.
我正在尝试让我的vb网站发送预订所需的各种数据访问数据库(.mdb文件)
I'm trying to get my vb website to send various bits of data that would be required for making bookings to an Access database (.mdb file)
如果在访问中我将条目部分更改为文本然后我的VB代码中的字符串将数据发送到形式绝对正常。
If in access I change the entry parts to Text then my strings in the VB code send the data to the form absolutely fine.
但是,如果我在VB表单中执行As Integer,则会抛出错误。我已经尝试了很多,并尝试验证我的文本,看看它们是否是数字,但似乎没有任何效果。
However if I do some As Integer in my VB form it throws an error. I've tried quite a few and tried to validate my text to see if they are numeric or not but nothing seems to work.
我只想拥有访问数据表propertys as Number并让我的VB与它一起工作。我正在粘贴我的代码片段,看看你是否可以发现我需要做的一些改变,让它做我想做的事。
I just want to be able to have the acess data table propertys as Number and get my VB to work with it. I'm pasting some snippets of my code to see if you could spot some changes I need to make for it to do what I want it to do.
Public Class clsCustomerBooking
Dim m_CustomerID As Long
Dim m_FirstName As String
Dim m_Surname As String
Dim m_FirstAddressLine As String
Dim m_SecondAddressLine As String
Dim m_City As String
Dim m_Postcode As String
'Dim m_BookingDate As Date
Dim m_CustomerUsername As String
Dim m_CustomerPassword As String
Dim m_CardNumber As String
Dim m_CardExpiryDate As String
Dim m_CvcNumber As String
Public Class clsCustomerBooking
Dim m_CustomerID As Long
Dim m_FirstName As String
Dim m_Surname As String
Dim m_FirstAddressLine As String
Dim m_SecondAddressLine As String
Dim m_City As String
Dim m_Postcode As String
'Dim m_BookingDate As Date
Dim m_CustomerUsername As String
Dim m_CustomerPassword As String
Dim m_CardNumber As String
Dim m_CardExpiryDate As String
Dim m_CvcNumber As String
'以上是我用于我的网站的一个类。
'The above is in a Class which i'm using for my website.
'以下是我在同一课程中所做的一些属性
'The following are some of the properties I have made in the same class
公共财产CardNumber()As String
获取¥b $ b 返回m_CardNumber
结束获取¥b $ b 设置(ByVal值为字符串)
m_CardNumber =值
结束集
结束物业
Public Property CardExpiryDate()As String
获取¥b $ b 返回m_CardExpiryDate
结束获取¥b $ b 设置(ByVal值为字符串)
m_CardExpiryDate = value
结束集
结束物业
公共财产CvcNumber()As String
获取¥b $ b 返回m_CvcNumber
结束获取¥b $ b 设置(ByVal值为字符串)
m_CvcNumber =值
结束集
结束属性
Public Property CardNumber() As String
Get
Return m_CardNumber
End Get
Set(ByVal value As String)
m_CardNumber = value
End Set
End Property
Public Property CardExpiryDate() As String
Get
Return m_CardExpiryDate
End Get
Set(ByVal value As String)
m_CardExpiryDate = value
End Set
End Property
Public Property CvcNumber() As String
Get
Return m_CvcNumber
End Get
Set(ByVal value As String)
m_CvcNumber = value
End Set
End Property
'以下是我在课程中包含的SQL语句
'The following is my SQL statement I have included in the class
Public Sub插入()
DB.Insert(" INSERT INTO Customer(FirstName,Surname,FirstAddressLine,SecondAddressLine,City,Postcode,CardNumber,CvcNumber,CustomerUsername,CustomerPassword)"& _
; " VALUES('"& FirstName&"','"& Surname&"','"& FirstAddressLine&"',' & SecondAddressLine&"','"& City&"','"& Postcode&"','"& CardNumber&
"' ,'"& CvcNumber&"','"& CustomerUsername&"','"& CustomerPassword&"')")
Public Sub Insert()
DB.Insert("INSERT INTO Customer (FirstName, Surname, FirstAddressLine, SecondAddressLine, City, Postcode, CardNumber, CvcNumber, CustomerUsername, CustomerPassword) " & _
"VALUES('" & FirstName & "','" & Surname & "', '" & FirstAddressLine & "','" & SecondAddressLine & "','" & City & "','" & Postcode & "','" & CardNumber &
"','" & CvcNumber & "','" & CustomerUsername & "','" & CustomerPassword & "')")
现在进入所有数据输入的网站页面代码
Now onto the website page code where all the data is inputted
私人功能DataIsOK()As Boolean
Dim Outcome As Boolean = False
如果txtFirstName.Text =""然后是
致电ShowMessage("缺少名字")
txtFirstName.Focus()
ElseIf txtSurname.Text =""然后是
致电ShowMessage("Missing surname")
txtSurname.Focus()
ElseIf txtFirstAddressLine.Text =""然后是
致电ShowMessage("缺少第一个地址行")
txtFirstAddressLine.Focus()
ElseIf txtSecondAddressLine.Text =""然后是
致电ShowMessage("缺少第一个地址行")
txtSecondAddressLine.Focus()
ElseIf txtPostcode.Text =""然后是
致电ShowMessage("缺少邮政编码")
txtPostcode.Focus()
ElseIf txtCustomerUsername.Text =""然后是
致电ShowMessage("您必须输入用户名")
txtCustomerUsername.Focus()
ElseIf txtCustomerPassword.Text =""然后是
致电ShowMessage("您必须输入密码")
txtCustomerPassword.Focus()
ElseIf txtCardNumber.Text =""然后是
致电ShowMessage("您必须输入卡号")
txtCardNumber.Focus()
ElseIf txtCardExpiryDate.Text =""然后是
致电ShowMessage("您必须输入到期日期")
txtCardExpiryDate.Focus()
ElseIf txtCvcNumber.Text =""然后是
致电ShowMessage("您必须从卡片背面输入安全代码")
txtCvcNumber.Focus()
'ElseIf MyCustomers.Exists(txtFirstName.Text,txtSurname.Text)然后
'调用ShowMessage(txtFirstName.Text&""& txtSurname.Text&"已存在")
否则为
结果=真实
结束如果
退货结果
结束功能
Private Sub btnSubmit_Click()
如果不是IsNumeric(txtCardNumber.Text)则为
MsgBox("请仅输入数字。",vb信息)
'你也可以考虑删除它。
txtCardNumber.Text =""
$
否则
如果不是IsNumeric(txtCvcNumber.Text)则为
MsgBox("请仅输入数字。",vb信息)
  '下一行清除课程的文本框
txtCvcNumber.Text =""
$
  结束如果
结束如果是
结束分
$ b 受保护的子btnSubmit_Click(ByVal sender As Object,ByVal e As System.EventArgs)处理btnSubmit.Click
如果DataIsOK()则为
MyCustomers.FirstName = txtFirstName.Text
MyCustomers.Surname = txtSurname.Text
MyCustomers.FirstAddressLine = txtFirstAddressLine.Text
MyCustomers.SecondAddressLine = txtSecondAddressLine.Text
MyCustomers.City = txtCity.Text
MyCustomers.Postcode = txtPostcode.Text
MyCustomers.CustomerUsername = txtCustomerUsername.Text
MyCustomers.CustomerPassword = txtCustomerPassword.Text
MyCustomers.CardNumber = txtCardNumber.Text
MyCustomers.CardExpiryDate = txtCardExpiryDate.Text
MyCustomers.CvcNumber = txtCvcNumber.Text
$
  ;      MyCustomers.Insert()
btnSubmit.Enabled = True
结束如果是
结束分
$
$
结束等级
Private Function DataIsOK() As Boolean
Dim Outcome As Boolean = False
If txtFirstName.Text = "" Then
Call ShowMessage("Missing first name")
txtFirstName.Focus()
ElseIf txtSurname.Text = "" Then
Call ShowMessage("Missing surname")
txtSurname.Focus()
ElseIf txtFirstAddressLine.Text = "" Then
Call ShowMessage("Missing First address line")
txtFirstAddressLine.Focus()
ElseIf txtSecondAddressLine.Text = "" Then
Call ShowMessage("Missing First address line")
txtSecondAddressLine.Focus()
ElseIf txtPostcode.Text = "" Then
Call ShowMessage("Missing Postcode")
txtPostcode.Focus()
ElseIf txtCustomerUsername.Text = "" Then
Call ShowMessage("You must enter a Username")
txtCustomerUsername.Focus()
ElseIf txtCustomerPassword.Text = "" Then
Call ShowMessage("You must enter a Password")
txtCustomerPassword.Focus()
ElseIf txtCardNumber.Text = "" Then
Call ShowMessage("You must enter a Card Number")
txtCardNumber.Focus()
ElseIf txtCardExpiryDate.Text = "" Then
Call ShowMessage("You must enter an Expiry Date")
txtCardExpiryDate.Focus()
ElseIf txtCvcNumber.Text = "" Then
Call ShowMessage("You must enter the security code from the back of the card")
txtCvcNumber.Focus()
' ElseIf MyCustomers.Exists(txtFirstName.Text, txtSurname.Text) Then
' Call ShowMessage(txtFirstName.Text & " " & txtSurname.Text & " is there already")
Else
Outcome = True
End If
Return Outcome
End Function
Private Sub btnSubmit_Click()
If Not IsNumeric(txtCardNumber.Text) Then
MsgBox("Please enter numbers only.", vbInformation)
'you may also consider erasing it
txtCardNumber.Text = ""
Else
If Not IsNumeric(txtCvcNumber.Text) Then
MsgBox("Please enter numbers only.", vbInformation)
'Next line clears the textbox ofcourse
txtCvcNumber.Text = ""
End If
End If
End Sub
Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
If DataIsOK() Then
MyCustomers.FirstName = txtFirstName.Text
MyCustomers.Surname = txtSurname.Text
MyCustomers.FirstAddressLine = txtFirstAddressLine.Text
MyCustomers.SecondAddressLine = txtSecondAddressLine.Text
MyCustomers.City = txtCity.Text
MyCustomers.Postcode = txtPostcode.Text
MyCustomers.CustomerUsername = txtCustomerUsername.Text
MyCustomers.CustomerPassword = txtCustomerPassword.Text
MyCustomers.CardNumber = txtCardNumber.Text
MyCustomers.CardExpiryDate = txtCardExpiryDate.Text
MyCustomers.CvcNumber = txtCvcNumber.Text
MyCustomers.Insert()
btnSubmit.Enabled = True
End If
End Sub
End Class
我将整个VB页面粘贴到以下链接上的pastebin:http://pastebin.com/X4MjzAsu
I'll paste the whole VB page on a pastebin on the following link : http://pastebin.com/X4MjzAsu
整个代码该课程是:http://pastebin.com/0EtxVtgL
The code for the whole of the class is : http://pastebin.com/0EtxVtgL
对不起该墙垃圾邮件,我现在感到绝望。有2天时间完成这项任务,是的,我已经把它留到了很晚但我已经知道了。
Sorry for the wall of spam, I'm feeling hopeless at the moment. Got 2 days to hand in this assignment and yeah, I've left it till very late but i've got my reasons.
推荐答案
我看不到您的数据库访问代码,但您应该使用命令参数而不是SQL语句中的变量。这将解决您在使用不同数据类型时遇到的问题。
I can't see your database access code, but you should be using Command Parameters instead of variables in your SQL statement. This will resolve the issue you are having when using different data types.
这篇关于从VB.net输入到Access数据库的编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!