|
查看: 1761|回复: 4
|
VB.net & Microsoft Sql问题
[复制链接]
|
|
|
本帖最后由 js_lee 于 21-10-2010 02:10 AM 编辑
我现在做到的是用button去捉资料。请问我要怎样改我才可以不用button直接standby在那里等捉资料??timer可以吗?我之前试过用timer捉可是一直有问题。希望各位帮帮我。。。谢谢^^下面是我的source code。我用的是Microsoft visual studio 2008跟它里面的microsoft sql database.
Public Class Form1
Private Sub loginButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles loginButton.Click
Dim connection As New SqlClient.SqlConnection
Dim command As New SqlClient.SqlCommand
Dim adaptor As New SqlClient.SqlDataAdapter
Dim dataset As New DataSet
Dim theDate As Date
Dim readit As Byte
Dim i As Integer
Label1.Text = ""
While (i <= 11)
readit = SerialPort1.ReadByte()
If readit > -1 Then Label1.Text = Label1.Text & readit
i += 1
End While
usernameTextBox.Text = Label1.Text
connection.ConnectionString = ("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Members.mdf;Integrated Security=True;User Instance=True")
command.CommandText = "SELECT * FROM [User] WHERE Username= '" & usernameTextBox.Text & "'AND Password='" & passwordTextBox.Text & "';"
connection.Open()
command.Connection = connection
adaptor.SelectCommand = command
adaptor.Fill(dataset, "0")
Dim count = dataset.Tables(0).Rows.Count
If count > 0 Then
MsgBox("Login succesful, welcome.", MsgBoxStyle.Information)
SerialPort1.RtsEnable = True
SerialPort1.DtrEnable = True
theDate = Date.Now()
TimerOpenCloseDoor.Enabled = True
Else
MsgBox("Incorrect login, please check your username and password.", MsgBoxStyle.Critical)
usernameTextBox.Clear()
passwordTextBox.Clear()
SerialPort1.RtsEnable = False
SerialPort1.DtrEnable = False
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If SerialPort1.IsOpen Then
SerialPort1.Close()
End If
Try
SerialPort1.Open()
Catch ex As Exception
MsgBox("Fail to open serial port")
End Try
End Sub
Private Sub TimerOpenCloseDoor_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerOpenCloseDoor.Tick
SerialPort1.RtsEnable = False
SerialPort1.DtrEnable = False
TimerOpenCloseDoor.Enabled = False
End Sub
End Class |
|
|
|
|
|
|
|
|
|
|
发表于 21-10-2010 11:18 PM
|
显示全部楼层
回复 1# js_lee
不太明白你的意识。。。如果不要button 按才读取资料,可以用form load 方法来试试看 |
|
|
|
|
|
|
|
|
|
|
发表于 22-10-2010 05:58 PM
|
显示全部楼层
我现在做到的是用button去捉资料。请问我要怎样改我才可以不用button直接standby在那里等捉资料??timer可 ...
js_lee 发表于 21-10-2010 02:07 AM 
1 楼正解, 请使用 Form Load Event, 不然就 你 Construct 的时候, 直接 Load 资料。 |
|
|
|
|
|
|
|
|
|
|
发表于 3-11-2010 11:47 AM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 3-11-2010 08:37 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|