0

m a newbie to vb.net and aspx and m trying to validate a login (employee id and date of birth) to a sql database and comin up with the following error (CommandText property has not been initialized). thanks for the help....

Protected Sub btn_memberlogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn_memberlogin.Click

        If txt_certno.Text = "" And DropDay.SelectedIndex = 0 Or DropMonth.SelectedIndex = 0 Or DropYear.SelectedIndex = 0 Then
            lbl_dob_error_msg.Visible = True
            Exit Sub
        Else

        End If
        'lbl_dob_error_msg.Visible = False
        'datetime = DropMonth.SelectedValue & "/" & DropDay.SelectedValue & "/" & DropYear.SelectedValue
        'MsgBox(FormatDateTime(datetime, DateFormat.LongDate))
        'MsgBox(datetime.ToString("dd MMMM yyyy"))

        Check_Cookie()


    End Sub

    Sub Check_Cookie()

        Dim StrConnString, sql
        'Dim conn As SqlConnection
        'Dim myCommand As SqlCommand
        Dim Comm As SqlCommand
        Dim dr As SqlDataReader
        Dim datetime As String
        Dim test_value As String
        test_value = DropDay.SelectedValue

        datetime = DropDay.SelectedValue & "/" & DropMonth.SelectedValue & "/" & DropYear.SelectedValue

        StrConnString = ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString
        Dim conn = New SqlConnection(StrConnString)
        conn.Open()

        Comm = New Data.SqlClient.SqlCommand("select * from members where Certificate=@Certificate and DateofBirth=@DateofBirth", conn)
        Comm.Parameters.Add("@Certificate", Data.SqlDbType.NVarChar).Value = txt_certno.Text
        Comm.Parameters.Add("@DateofBirth", Data.SqlDbType.DateTime).Value = datetime

        Comm = New SqlCommand(sql, conn)
        'Comm.Connection = conn
        dr = Comm.ExecuteReader()

        If dr.Read() Then
            Session("Class") = dr("mc_color").ToString()
            Session("CertID") = dr("cert_no").ToString()
            Session("DOB") = dr("dob").ToString()
            Response.Redirect("~/pages/Myaccount.aspx")
        Else
            lblerror.Text = "Incorrect Certification number or Date of Birth! Please try again"
        End If
        dr.Close()
        conn.Close()
end sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load



        'populates the day
        DropDay.ClearSelection()
        DropDay.Items.Add("Day")
        Dim dy As Integer
        For dy = 1 To 31
            DropDay.Items.Add(dy)
        Next

        'populates the month
        Dim dtfi As New DateTimeFormatInfo()
        DropMonth.Items.Add("Month")
        For month As Integer = 1 To 12
            Dim li As New ListItem()
            li.Text = dtfi.GetMonthName(month)
            li.Value = month
            DropMonth.Items.Add(li)
        Next

        'populates the year
        'Dim yr As New DateTimeFormatInfo()
        Dim yr As Integer
        Dim first_yr As Integer
        DropYear.Items.Add("Year")
        yr = Year(Now)
        first_yr = yr - 100

        For i = first_yr To yr
            DropYear.Items.Add(i)
        Next



        If Not IsPostBack Then
            lbl_dob_error_msg.Visible = False
        Else
        End If

    End Sub
1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by smdhas
0

further to the above query, no matter what day i select, the value returned is always "Day" and not the day as in day i've selected e.g if 14/1/1976 is selected, Day/1/1976 is returned.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.