我是VB.Net&的新手需要一些帮助 [英] I am new in VB.Net & Need Some Help

查看:75
本文介绍了我是VB.Net&的新手需要一些帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在搜索插入了查询的记录时遇到问题,但是它生成一个错误,提示您缺少一个或多个查询,请帮助我.我正在附加代码.

I have a problem while searching the record I have inserted a Query but it is generating an Error that One or More Query is missing please Help me. I am Attaching the Code.

NameTextBox.Text = ""
     Dim vSearch As String = InputBox("Enter Integer number to search name:")
     If vSearch <> "" Then
         cmdOLEDB.CommandText = "SELECT Name, Address FROM Patient WHERE Name=" & CStr(vSearch)
         cmdOLEDB.Connection = cnnOLEDB
         cmdOLEDB.ExecuteReader("Name")
         If rdrOLEDB.Read = True Then
             'Do While rdrOLEDB.Read
             NameTextBox.Text &= rdrOLEDB.Item(0).ToString & " " & rdrOLEDB.Item(1).ToString
             rdrOLEDB.Close()
             Exit Sub
             'Loop
         Else
             MsgBox("Record not found")
             rdrOLEDB.Close()
             Exit Sub
         End If
     Else
         MsgBox("Enter search value.")
         Exit Sub
     End If
 End Sub
End Class

推荐答案

首先,将来不要问这样的问题:我是VB.Net的新人,并且需要一些帮助" 不是一个好标题.尝试使标题尽可能少地描述问题. "OLEDB问题-缺少一个或多个查询" 可能更好.这样,只有具有OLEDB经验并且可能知道问题所在的人员才需要阅读它.否则,您会浪费我们的时间-在寻求帮助方面不是一个好的开始! :laugh:

其次,您需要阅读命令:OleDbCommand.ExecuteReader没有接受字符串的重载,并且所有这些都返回您忽略的OleDbReader.尝试稍微更改代码以使用返回的结果:
Firstly, in future, do not ask a question like that: "I am new in VB.Net & Need Some Help" is not a good title. Try to make the title describe the problem in as few a word as possible. "OLEDB problem - One or more query is missing" might be better. That way, only people with experience of OLEDB and who might know what the problem is need to read it. Otherwise you waste our time - not a good start to getting help on a problem! :laugh:

Secondly, you need to read up on your commands: OleDbCommand.ExecuteReader does not have an overload that accepts a string, and all of them return a OleDbReader which you are ignoring. Try changing your code a little to use the returned result:
cmdOLEDB.Connection = cnnOLEDB
cmdOLEDB.ExecuteReader("Name")
If rdrOLEDB.Read = True Then

成为:

cmdOLEDB.Connection = cnnOLEDB
rdrOLEDB = cmdOLEDB.ExecuteReader()
If rdrOLEDB.Read = True Then

这个问题应该消失.


我看到两个问题:
1.您的查询形成:where子句未定义正确的字符串.
I see two issues:
1. Your query formed: where clause does not have proper string defined.
cmdOLEDB.CommandText = "SELECT Name, Address FROM Patient WHERE Name='" & CStr(vSearch) &"'"



2.您的DataReader会说一些名称".它不应具有任何参数.



2. Your DataReader says some ''Name''. It should not have any parameter.

rdrOLEDB = cmdOLEDB.ExecuteReader()



尝试看看.



Try and see.


这篇关于我是VB.Net&amp;的新手需要一些帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆