查找数据库问题

luxiaochuang 2009-03-29 01:32:53
输入字符查找数据库中内容,如果有内容则返回内容,如果没有则现在该字符
下面是我写的函数 如果数据库中有内容的已经可以成功返回 但是没有对应记录的则没有显示原来输入的字符,请帮帮忙看看是错在哪里
主要是 ElseIf (str = "") Then
TextBox2.Text = TextBox2.Text + strWords(i)
这条语句就是没有作用

代码如下:
Private Function SplitStringIntoWords() As Integer
Dim strComplete As String = TextBox3.Text '"This-is a complete sentence"
Dim strWords() As String
Dim strSeparators() As Char = {" "c, "-"c}
strWords = strComplete.Split(strSeparators)
Dim i As Integer
For i = 0 To UBound(strWords)
Try
Mycn.ConnectionString = sConnString
Mycn.Open()
Dim sComm As New SqlCommand("select word from tblAddCode where code= '" & strWords(i) & "'", Mycn)
Dim MydataReader As SqlDataReader = sComm.ExecuteReader
Dim str As String
Dim t As Integer
While MydataReader.Read
For t = 0 To MydataReader.FieldCount - 1
str = MydataReader.Item(t)
If (str <> "") Then
TextBox2.Text = TextBox2.Text + str
ElseIf (str = "") Then
TextBox2.Text = TextBox2.Text + strWords(i)
End If
Next
End While
Mycn.Close()
Catch myinformation As SqlException
MessageBox.Show(myinformation.Message)
End Try

Next

End Function
...全文
50 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
elite2018 2009-03-29
  • 打赏
  • 举报
回复
use:

if exists( ....)

your sql
luxiaochuang 2009-03-29
  • 打赏
  • 举报
回复
还是不行啊 改成trim(str) 我是想是不是这条语句str = "" 不能判断查找出来的数据是空啊
还有这条语句在代码中的位置对不对啊
itcrazyman 2009-03-29
  • 打赏
  • 举报
回复
1.你先确定是否执行了 ElseIf (str = "") Then
不妨改成trim(str)="" 试试
2.确定strWords(i)中是否有数据可以输出到前台看下

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧