关于Microsoft Access和Visual Basic.NET之间的数据读取器的问题 [英] Questions Regarding Data Reader Between Microsoft Access and Visual Basic.NET
问题描述
我可以知道如何读取所有数据在我的Microsoft Access Visual Basic.NET中?我只能读取一行数据但是另一行数据我无法读取它。
请为我解决...谢谢!
下面是我的代码和我的数据库
Search2.CommandText =" Select * from 1231232 Where date ='" &安培; ListBox1.Text& "";"
Search2.Connection = cnnOleDb Dim dr As OleDbDataReader = Search2.ExecuteReader如果dr.Read = True则Button2.BackColor = Color.Red End如果dr.Close()
推荐答案
你好,
这是一个基本模式,请注意字段日期周围的方括号,因为我认为这是一个保留令牌。还要注意使用WHERE条件值的参数,你永远不应该使用字符串连接,因为这可能导致a)unescapted撇号
b)sql注入。
Here is a basic pattern, note the square brackets around the field date as I believe is this a reserve token. Also note the use of a parameter for the WHERE condition value, you should never use string concatenation as this can lead to a) unescapted apostrophes b) sql injection.
Public Function Demo(pSearchValue As string) As Boolean
Using cn As New OleDbConnection With {.ConnectionString = "TODO"}
Using cmd As New OleDbCommand With {.Connection = cn}
cmd.CommandText = "SELECT [date] FROM SomeTable WHERE [Date] = ?"
cmd.Parameters.AddWithValue("?",pSearchValue)
cn.Open()
Dim reader = cmd.ExecuteReader()
Return reader.HasRows
End Using
End Using
End Function
这篇关于关于Microsoft Access和Visual Basic.NET之间的数据读取器的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!