使用文本框作为过滤器填充DataGrid以显示过滤后的交易 [英] filling a DataGrid to show filtered transactions using a textbox as the filter

查看:57
本文介绍了使用文本框作为过滤器填充DataGrid以显示过滤后的交易的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单上有一个文本框,一个网格和一个按钮.
我想使用用户输入的textbox.text在用户单击按钮时填充数据网格.

我试图在sql WHERE子句中添加textbox.text,但是什么也没发生:

I have a textbox, a datgrid and a button on my form.
I want to use the textbox.text entered by the user to fill the data grid when the user clicks the button.

I have tried to add the textbox.text in the sql WHERE clause but nothing happens:

Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'Test_NAB_transDataSet.Split' table. You can move, or remove it, as needed.
        Me.SplitTableAdapter.Fill(Me.Test_NAB_transDataSet.Split)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.SplitTableAdapter.NABid(Me.Test_NAB_transDataSet.Split)
    End Sub
End Class



所以...在查询生成器中,我有以下内容:



so... in the Query Builder I have the following:

SELECT        ID, NABTransID, Category, SubCategory, Amount
FROM            Split
WHERE        (NABTransID = '" + Me.TextBox1.Text + "')




在高级感谢
Stephen




thanks in advanced
Stephen

推荐答案

在没有看到实际代码的情况下,很难分辨出问题所在.由于我不知道您是如何填充网格的,因此我必须给您级联的解决方案:
Without seeing you actual code, it is difficult to tell what the problem is. Since I don''t know how you are filling your grid, I have to give you a concatenated solution:
string strSelect = "SELECT * FROM SplitTrans WHERE nabID=''" + TextBox1.Text + "''";

但是,您应该改用参数化查询,以避免意外或故意的SQL注入攻击.不过,我们需要查看相关的代码片段来告诉您如何执行此操作.

However, you should use Parametrized queries instead, to avoid accidental or deliberate SQL Injection attack. We would need to see the relevant code fragment to tell you how to do that, though.


这篇关于使用文本框作为过滤器填充DataGrid以显示过滤后的交易的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆