我正在使用基于VB.NET和MySQL的基本银行系统,并且在交易历史记录中显示特定数据时遇到问题。问题是,我想显示从特定日期到特定日期(如边界或某物)发生的所有事务。这是我想要使用的代码行,但我无法使其工作:
Dim view As String ="从tblhistory中选择*,其中accountnumber ='" &安培; txtAccount.Text& "'和日期一样'" &安培; txtFrom.Text& "%'或约会,如'" &安培; txtTo.Text& "'"
我想到的概念是,使用LIKE运算符,使用户输入的边界显示用户想要查看的唯一特定事务,而不是显示所有用户的事务并且无法查找那个特定的交易。
你们能帮我解决这个问题吗?非常感谢你。美好的一天。顺便提一下,这是完整的代码:
Public Class TransactionHistory
Public rights As String
Public log As String
Public accountnum As String
Private Sub btnProceed_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProceed.Click
lvHistory.Items.Clear()
Dim con As New MySqlConnection("server = localhost ; uid = root ; database = dbbank")
Dim view As String = "select * from tblhistory where accountnumber = '" & txtAccount.Text & "' and date like '" & txtFrom.Text & "%' or date like '" & txtTo.Text & "'"
Dim cmd As New MySqlCommand(view, con)
con.Open()
Dim data As MySqlDataReader = cmd.ExecuteReader()
While data.Read()
Dim entries As ListViewItem
entries = lvHistory.Items.Add(data(0))
With entries
.SubItems.Add(data(1))
.SubItems.Add(data(2))
.SubItems.Add(data(3))
.SubItems.Add(data(4))
End With
End While
If rights = "manager" Then
Manager.Show()
Me.Close()
ElseIf rights = "teller" Then
Teller.Show()
Me.Close()
End If
End Sub
Private Sub cmbType_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbType.SelectedIndexChanged
lvHistory.Items.Clear()
Dim con As New MySqlConnection("server = localhost ; uid = root ; database = dbbank")
Dim view As String = "select * from tblhistory where accountnumber = '" & txtAccount.Text & "' and transactiontype = '" & cmbType.SelectedItem & "'"
Dim cmd As New MySqlCommand(view, con)
con.Open()
Dim data As MySqlDataReader = cmd.ExecuteReader()
While data.Read()
Dim entries As ListViewItem
entries = lvHistory.Items.Add(data(0))
With entries
.SubItems.Add(data(1))
.SubItems.Add(data(2))
.SubItems.Add(data(3))
.SubItems.Add(data(4))
End With
End While
End Sub
Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
Me.Close()
End Sub
Private Sub TransactionHistory_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtAccount.Text = accountnum
End Sub
结束班
答案 0 :(得分:0)
'或'导致你的问题。它实际上就像要求这个帐户的所有内容以及像FROM"这样的日期。并且还给我带来了像TO"这样的日期。在日期条件周围添加括号可以解决这个问题。
我认为这可以解决一些问题:
NSManagedObjectContext *context = [self managedObjectContext];
NSManagedObject *object = [NSEntityDescription insertNewObjectForEntityForName:@"EY_Appliance" inManagedObjectContext:context];
[object setValue:self.applianceIdValue forKey:@"applianceId"];
[object setValue:self.applianceNameValue forKey:@"applianceName"];
[object setValue:self.wattsValue forKey:@"watts"];
[object setValue:self.amountPerWattsValue forKey:@"amountPerWatts"];
NSError *error = nil;
if (![context save:&error]) {
NSLog(@"Saving Failed with error %@", error);
}
但是,请记住,这只会查找特定日期的交易,而不是日期之间的交易。
也可以尝试
Dim view As String = "select * from tblhistory where accountnumber = '"
& txtAccount.Text & "' and (date like '" & txtFrom.Text & "%' or date like '" & txtTo.Text & "')"
最后,使用参数。