查找数据库问题

luxiaochuang luxiaochuang 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
输入字符查找数据库中内容,如果有内容则返回内容,如果没有则现在该字符
下面是我写的函数 如果数据库中有内容的已经可以成功返回 但是没有对应记录的则没有显示原来输入的字符,请帮帮忙看看是错在哪里
主要是 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
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
luxiaochuang
VB 16,719 成员 110,520 内容