查找数据库问题
输入字符查找数据库中内容,如果有内容则返回内容,如果没有则现在该字符
下面是我写的函数 如果数据库中有内容的已经可以成功返回 但是没有对应记录的则没有显示原来输入的字符,请帮帮忙看看是错在哪里
主要是 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