请帮我在OLEDB中搜索列中的文本字符串 [英] Please Help me search a Text string in a column With OLEDB

查看:66
本文介绍了请帮我在OLEDB中搜索列中的文本字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  private   void  toolStripButton3_Click_1(对象发​​件人,EventArgs e)
{

搜索(toolStripTextBox1.Text);

}
public DataTable Search( string value
{

DataTable table = new DataTable();
table =(DataTable)dataGridView1.DataSource;
字符串 Param = SELECT Firstname FROM + table + WHERE Firstname LIKE% + + ;
table.Select(Param);
return 表;

}



任何人都可以帮我解决方案

以上就是我到目前为止/>
谢谢你

解决方案

你好会员9430088,



首先是行:

 table.Select(Param); 



返回一个DataRow数组,您目前无法做任何事情,

尝试收集它并提取您需要的数据:



例如

 DataRow [] ResultArray = table.Select(searchFilterHere); 
// 使用ResultArray执行任务





如果您打算将结果作为新的DataTable返回,您需要执行以下操作:



  foreach (DataRow row  in  rowArray)
{
dataTable.ImportRow(row);
}







如果这有帮助,或者您需要进一步澄清,请告诉我。 。



干杯,

Edo


尝试:

< pre lang =c#> 字符串 Param = SELECT名字FROM + table + WHERE名字LIKE'% + value + %';

报价是必需的。但请注意,空间将是重要的 - 它将匹配任何后跟空格,后跟文本,后跟空格,然后是任何内容。



您还需要非常仔细地检查值的内容,以避免SQL注入攻击。


private void toolStripButton3_Click_1(object sender, EventArgs e)
        {
           
                Search(toolStripTextBox1.Text);
           
        }
        public DataTable Search(string value)
        {
           
            DataTable table = new DataTable();
            table = (DataTable)dataGridView1.DataSource;
            String Param = "SELECT Firstname FROM " + table + " WHERE Firstname LIKE % " + value + " %";
            table.Select(Param);
            return table;
           
        }


Can anyone please help me with a solution
The above is what i have so far
Thank you

解决方案

Hi Member9430088,

Firstly the line:

table.Select(Param); 


returns an array of DataRow with which you currently don''t do anything,
try collecting it and extracting the data you need:

e.g.

DataRow[] ResultArray = table.Select(searchFilterHere);
// Do stuff with your ResultArray 



if you intended to return the result as a new DataTable you''ll need to do something like this:

foreach (DataRow row in rowArray) 
{
   dataTable.ImportRow(row);
}




Let me know if this helps, or if you need any further clarifications.

Cheers,
Edo


Try:

String Param = "SELECT Firstname FROM " + table + " WHERE Firstname LIKE '% " + value + " %'";

The quotes are required. But be aware that the spaces will be significant - it will match "anything followed by a space, followed by your text, followed by a space, followed by anything".

You will also need to check the contents of value very carefully to avoid SQL Injection attacks.


这篇关于请帮我在OLEDB中搜索列中的文本字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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