【发布时间】:2015-11-22 21:18:49
【问题描述】:
我正在尝试在我的数据库中创建和保存配置文件详细信息,但我收到一条错误消息,提示“ExecuteReader 需要一个打开且可用的连接。连接的当前状态已关闭。我们将不胜感激任何帮助。这里是我的代码。
Imports System.Data.OleDb
Public Class Profile
Public profileConnection As New OleDbConnection
Public profileCommand As New OleDbCommand
Dim anewProfile As New PlayerProfile()
Private Sub CreateProfileButton_Click(sender As Object, e As EventArgs) Handles CreateProfileButton.Click
profileCommand.Connection = profileConnection
profileCommand.CommandText = "select Email from Players where Email = '" & EmailTextBox.Text & "'"
Dim profileDataReader As OleDbDataReader = profileCommand.ExecuteReader() 'getting error on this line
If profileDataReader.Read() Then
MsgBox("This email already exits.")
profileDataReader.Close()
Exit Sub
End If
【问题讨论】:
-
你在哪里调用profileConnection.Open?
-
我不认为我这么叫
-
这段代码很容易受到sql注入攻击。它实际上是在乞求被黑。
-
我知道哈哈。这只是我正在做的一个小项目。没什么特别的
标签: .net vb.net visual-studio