We help IT Professionals succeed at work.
Get Started

what am i doing wrong here - date from database asp.net

180 Views
Last Modified: 2015-02-28
here is my vb code
Imports System.Data.SqlClient

Partial Class main
    Inherits System.Web.UI.Page

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

        Dim ConnectionString As String = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("dbconn").ToString()
        Dim dateval As DateTime = Now.Date.ToString
        Dim MyConn As New System.Data.SqlClient.SqlConnection(ConnectionString)
        Dim MyComm As New System.Data.SqlClient.SqlCommand("SELECT * FROM [dbo].[doctime] WHERE date= " + "'" + dateval + "'", MyConn)

        MyConn.Open()
        Dim DataReader As System.Data.SqlClient.SqlDataReader = MyComm.ExecuteReader()
        'Dim format As String = "MM/DD/YY"
        While (DataReader.Read())

            date_label.Text = DataReader("Date")
            'box1_lbdate_1.Text = dateval.ToString
            Doc1name.Text = DataReader("Doc1_Name").ToString
            Doc1time.Text = DataReader("doc1_time").ToString
            Doc2name.Text = DataReader("doc2_name").ToString
            Doc2time.Text = DataReader("doc2_time").ToString

            If String.IsNullOrWhiteSpace(Doc2name.Text) Then
                Doc2name.Visible = False
                Doc2time.Visible = False
            End If


        End While
        DataReader.Close()
        MyConn.Close()


    End Sub
End Class

I keep getting this error
[embed=file 900763]

Open in new window


my database has the following fields
table name is doctime

then it has a primary key of id
then date as type text
then doc1name as type text
doc1time as type text
doc2name as type text
doc2time as type text.

I had it working before but made some changes and for the life of me no idea what broke it. thanks!
date-select-sql-error.PNG
Comment
Watch Question
Fixer of Problems
CERTIFIED EXPERT
Most Valuable Expert 2014
Commented:
This problem has been solved!
Unlock 2 Answers and 3 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE