如何从访问数据库中检索数据

编程入门 行业动态 更新时间:2024-10-27 20:34:01
本文介绍了如何从访问数据库中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我尝试使用VB 2015从我的访问数据库中检索数据,所有数据都能够在运行时在表单中的数据网格视图中显示,但是我使用COMBO BOXES AND PICTURE BOX从表单中收集的数据无法显示在表格中的组合框和图片框中,我可以立即编辑或删除它。 请帮助我, 提前感谢。 我尝试了什么:

I try retrieve data from my access data base using VB 2015, all the data where able to displayed on data grid view in the form when run, but the data i collect from the form using COMBO BOXES AND PICTURE BOX could not displayed on the combo box and picture box in the form so that i could be able to edit it or delete it using the form instantly. please help me, thanks in advance. What I have tried:

Private Sub ButtonSEARCH_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonSEARCH.Click If TextBoxSEARCH.Text = "" Then MsgBox("Please check, the SEARCH space is blank", vbExclamation) Else myConnection.Open() Dim str As String str = "SELECT * FROM harry WHERE (Yname ='" & TextBoxSEARCH.Text & "')" Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection) dr = cmd.ExecuteReader If dr.Read Then TextBoxNAME.Text = dr("Yname").ToString TextBoxPHONE.Text = dr("Phone").ToString TextBoxEMAIL.Text = dr("Email").ToString TextBoxADDRESS.Text = dr("Address").ToString TextBoxDURATION.Text = dr("Duration").ToString TextBoxHOMEcongr.Text = dr("Homecongr").ToString TextBoxSPOUSEphone.Text = dr("Spousephone").ToString ComboBoxGENDER.Text = dr("Gender").ToString ComboBoxMARITALstatus.Text = dr("Maritalstatus").ToString ComboBoxVISITOR.Text = dr("Visitor").ToString Dim conn As New OleDb.OleDbConnection Dim reader As OleDb.OleDbDataReader conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=DIRECTORY.accdb" conn.Open() cmd = conn.CreateCommand() cmd.CommandText = "SELECT * FROM harry WHERE (Yname ='" & TextBoxSEARCH.Text & "')" reader = cmd.ExecuteReader If reader.Read Then Dim ms As New MemoryStream() Dim arrimage() As Byte If (PictureBoxMAIN.Image IsNot Nothing) Then PictureBoxMAIN.Image.GetType() arrimage = ms.GetBuffer ms.Close() End If dr.Close() End If reader.Close() conn.Close() cmd.Dispose() conn.Dispose() End If myConnection.Close() TextBoxSEARCH.Text = "" End If End Sub<pre>

推荐答案

永远不要通过连接用户输入来构建SQL查询,它被命名为SQL注入,它对您的数据库很危险并且容易出错。 名称和程序中的单引号崩溃。 SQL注入 - 维基百科 [ ^ ] SQL注入 [ ^ ] Never build an SQL query by concatenating with user inputs, it is named "SQL injection", it is dangerous for your database and error prone. A single quote in a name and your program crash. SQL injection - Wikipedia[^] SQL Injection[^]

更多推荐

如何从访问数据库中检索数据

本文发布于:2023-10-28 05:38:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1535686.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库中   数据

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!