السلام عليكم
ظهرت عندي مشكلة في ولا اعرف اين المشكلة تحديدا هل هي في select statement ام عند استخدام ExecuteReader()
حيث تظهر لي رسالة الخطأ التالية
Invalid attempt to read when no data is present
علما اني استخدم Microsoft visual studio 2005
---------
وهذا الكود:
<%@ Page Language="VB" MasterPageFile="~/MasterPage.master" Title="Untitled Page" %>
<script runat="server">
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'LOCAL VARIABLES
Dim id As String = TextBox1.Text
Dim password As String = TextBox2.Text
'----creating the connection
Dim cons As String = ConfigurationManager.ConnectionStrings("votingdbConnectionString").ConnectionString
Dim con As New Data.SqlClient.SqlConnection
con.ConnectionString = cons
'--------creating the command
Dim comSel As New Data.SqlClient.SqlCommand
comSel.CommandText = "SELECT [CandidateName] FROM [CANDIDATE] WHERE ([CandidateID] = '" & id & "' AND [CandidatePassword] = '" & password & "')"
comSel.CommandType = Data.CommandType.Text
comSel.Connection = con
Try
con.Open()
Dim rd As Data.SqlClient.SqlDataReader = comSel.ExecuteReader()
Dim canName As String = rd.GetValue(1) ' get from column 1(second column) in DB
If (rd.Read() = True) Then
Session("name") = canName
'moving from page to page
Server.Transfer("cand-Page.aspx")
End If
rd.Close()
Catch ex As Exception
Label4.Text = ex.Message
Label4.Visible = True
Finally
End Try
con.Close()
End Sub
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<br />
دخول المرشحين<br />
<br />
<asp:TextBox ID="TextBox1" runat="server">1234567891</asp:TextBox>
<asp:Label ID="Label1" runat="server" Text="رقم السجل المدني"></asp:Label>
<br />
<asp:TextBox ID="TextBox2" runat="server" OnTextChanged="TextBox2_TextChanged" TextMode="Password"></asp:TextBox>
<asp:Label ID="Label2" runat="server" Text="كلمة المرور"></asp:Label> <br />
<asp:Label ID="Label4" runat="server" Text="Label" Visible="False"></asp:Label>
<br />
<asp:Button ID="Button1" runat="server" Text="الدخول" OnClick="Button1_Click" />
<br />
</asp:Content>-------
ارجو مساعدتي في معرفة الخطأ,,, وشكرا مقدما :)