使用sql数据库搜索字符串,多行文本框中的子字符串 [英] search substring in a string ,multiline textbox using sql database
本文介绍了使用sql数据库搜索字符串,多行文本框中的子字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i有一个多行文本框和一个有100000条记录的sql数据库..
我的问题怎么样使用多行文本框搜索字符串中的子字符串,该文本框与sql数据库进行200行比较...
thnnxs提前
i have one multiline textbox and one one of sql database having 100000 records in it ..
my question how to search substring in a string using a multiline textbox which having 200 line compare with sql database ...
thnnxs in advance
推荐答案
是的,我想检查多行文本框中的每一行,查找一行中的子字符串,以查看它是否存在于数据库中......
所以只需循环...
"yes i want check each line in the multiline textbox for a substring in a string of line to see if it exists in the db ..."
So just loop through...
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
foreach (string line in myMultiLineTextBox.Lines)
{
using (SqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM MyTable WHERE MyColumn = @LINE", con))
{
cmd.Parameters.AddWithValue("@LINE", line);
if ((int)cmd.ExecuteScalar() != 0)
{
// Found one!
}
}
}
}
plzzz提供vb.net代码而不是c#
删除分号,它几乎就在那里......
"plzzz provide vb.net code not c#"
Remove the semicolons, and it's pretty much there...
Using con As New SqlConnection(strConnect)
con.Open()
For Each line As String In myMultiLineTextBox.Lines
Using cmd As New SqlCommand("SELECT COUNT(*) FROM MyTable WHERE MyColumn = @LINE", con)
cmd.Parameters.AddWithValue("@LINE", line)
If CInt(cmd.ExecuteScalar()) <> 0 Then
' Found one!
End If
End Using
Next
End Using
这篇关于使用sql数据库搜索字符串,多行文本框中的子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文