使用MS Access和VB选择语句时出错 [英] Error in Select Statement using MS Access and VB

查看:102
本文介绍了使用MS Access和VB选择语句时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图通过使用来自客户端的ID获取记录,但它一直告诉我没有找到记录



这里是代码:



I''m trying to get a record by using the Id from the client but it keeps telling me no record found

here is the code:

Private Sub btnBuscar_Click(sender As Object, e As EventArgs) Handles btnBuscar.Click
       Try

           Dim str As String ' str = string "string"
           str = "SELECT * FROM tblClientes WHERE (NumId = " & txtNumID.Text & ")"
           'Instruccion de SQL
           Dim comando As OleDbCommand = New OleDbCommand(str, miConeccion)
           dataReader = comando.ExecuteReader
           While dataReader.Read()
               txtNombre.Text = dataReader("Nombre").ToString
               txtApe.Text = dataReader("Apellido").ToString
               txtCiudad.Text = dataReader("Ciudad").ToString
               txtNumT.Text = dataReader("Telefono").ToString
               txtSS.Text = dataReader("Seguro Social").ToString
               txtZipCode.Text = dataReader("ZipCode").ToString
           End While

       Catch ex As Exception
           'mensaje en caso de error;
           MsgBox("No se encontro la informacion")
       End Try
       miConeccion.Close()
   End Sub



我大部分时间都习惯使用C#而不习惯VB而且我不知道它是支架还是东西否则,谢谢


I''m not used to VB most of the time I use C# and I do not know if it''s a bracket thing or something else, Thank You

推荐答案

如果说没有找到记录,那是因为没有记录,NumId批处理你在文本框中输入的文本。检查你的数据 - 文本框内容和数据库。



并且不要这样做!

不要连接用于构建SQL命令的字符串。它让您对意外或故意的SQL注入攻击持开放态度,这可能会破坏您的整个数据库。改为使用参数化查询。





[edit]

如果你的意思是你得到了消息框中写着No se encontro la informacion,那么您需要查看异常细节,方法是将其添加到消息框文本中,或者通过查看调试器 - 如果我们不这样做,我们就无法提供准确的建议知道它在抱怨什么!

[/ edit]
If it is saying that no records are found, it is because there are no records where the NumId batch the text you typed in the text box. Check your data - both the text box content and the database.

And don''t do it like that!
Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.


[edit]
If what you mean is that you get the message box saying "No se encontro la informacion", then you need to look at the exception detail, either by adding it to the message box text, or by looking with the debugger - we can''t give accurate advice if we don''t know what it is complaining about!
[/edit]


这篇关于使用MS Access和VB选择语句时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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