|
-
Mar 17th, 2005, 07:21 AM
#1
Thread Starter
New Member
Database bug...
i am writing a program that allows the user to set the search criteria when accessing my data base. it is a simple one table 4 column DB. this is a VERY simple translation program that is intended to translate a whole sentence. the sentence is split up into an array and each word is processed indiviually. the problem occurs when the user inputs a word that is not in the DB. it will act as if it skipped over that word.
for example: if i was translating from engish to english...(just to point this bug out)... the sentence "the boy is sitting on the red table" it would be translated into "the is on the red table" because both "boy" and "sitting" are not listed in the data base... what expresion or boolean term can i use to show on the front end that this has happened?
code to follow:
VB Code:
Private Sub btnTransForm1_Click(ByVal sender As _
System.Object, ByVal e As System.EventArgs) Handles btnTransForm1.Click
Dim Words() As String = RemoveUnwantedCharacters(txtLangIn.Text).Split(" ")
Dim Output As String
Dim n As Integer = 0
txtLangOut.Clear()
For n = 0 To Words.Length - 1
Try
'data base call code
oledbcon.Open()
strSQL = ("SELECT " & cbxLangOut.Text & " FROM English WHERE " _
& cbxLangIn.Text & " = '" & Words(n) & "'")
'Output = IsTableNull(oledbcon, "English", strSQL)
'MsgBox(Output, , " ")
cmd = New OleDb.OleDbCommand(strSQL, oledbcon)
objRead = cmd.ExecuteReader
While objRead.Read
If IsDBNull(objRead(cbxLangOut.Text)) Then
MsgBox("Error", , " ")
Else
Me.txtLangOut.Text &= objRead(cbxLangOut.Text) & " "
End If
End While
objRead.Close()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "")
Catch ex As System.Data.SqlTypes.SqlNullValueException
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "")
Finally
oledbcon.Close()
'For i As Integer = 0 To Output.Length - 1
'txtLangOut.Text &= Output(i) + " "
'Next
End Try
Next
gbIn.Text = cbxLangIn.Text
gbOut.Text = cbxLangOut.Text
End Sub
as you can see i have been trying to see if it is coming out as an Null value but nothing i have tryed has worked... any help would be greatly appreciated.
Thanks
-Will-
PS. i honestly don't know enough to really tweak code with database calls, any good books i can get to that would be useful and maybe instructional?
Last edited by Mysticshade; Mar 17th, 2005 at 07:25 AM.
-
Mar 17th, 2005, 07:42 AM
#2
Thread Starter
New Member
Re: Database bug...
 Originally Posted by kulrom
id you are using & " " instead & "" you should use trim to remove all blank/white space so it would only make you new complications there, so keep using "" - empty string
kind regards 
if i use:
VB Code:
txtLangOut.Text = objRead(cbxLangOut.Text) & ""
my output is only the last word that is being processed...
if i use what i have the whole sentence is sent to the text box and it doesn't look like: "theyellowhatisontheredtable" or "table"
so please explain... i don't understand.
-Will-
-
Mar 17th, 2005, 07:47 AM
#3
Thread Starter
New Member
Re: Database bug...
VB Code:
While objRead.Read
if IsDBNull(objReader(cbxLangOut.Text)) then
msgBox("Please select language! ")
Exit If
cbxLangOut.Focus()
else
txtLangOut.Text = objRead(cbxLangOut.Text) & ""
end if
End While
objRead.Close()
didn't fix the bug... it still runs straight through and outputs Null to txtLangOut, when i enter a word that is not located in the table.
i just want to be able to tell the user that the word is not in the table, but the catch exception should be doing that, right?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|