VB.NET Class Properties

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I have a class called clsPerson. A property of this class is Date_Of_Birth
(DOB).

In my Access Database the field is date/Time data Type. I am trying to set
the class property DOB to the contents of a textbox (txtDOB.text) that the
user entered.

so I have my:
Dim objPerson as New clsPerson
objPerson.DOB = txtDOB.text

Then I run my SQL statement to update my database using the property from
inside the class. This does not work. I get NO errors, just that the property
is enty.

Any Suggustions on what i am doing wrong?

Thanks in Advance,
Mark
 
Can you post your update query? In access doesn't the date field have to be
enclosed in #? "#2005/1/12#'

Chris
 
Yes it does have to be enclosed in #'s. I have this done. If I pass the date
from the textbox in as a agurement it works fines, but pass itno the qiery
via a class property, it doesn't work. When I response.write the class
property out to the screen it is entry.

??
 
What does the query look like just before you send it to the database? What
is the datatype of DOB? It helps if you post snippets of code that show the
problem.

Chris
 
Hi Chris,

Here's my SQL Query String:

strSQL = "SELECT InterviewAvailability.InterviewAvailabilityID,
InterviewAvailability.UserAccountID, UserAccount.FullName,
UserAccount.Username, InterviewAvailability.DOB,
InterviewAvailability.StartTime, InterviewAvailability.EndTime,
InterviewAvailability.UnavailableTypeID, NonAvailableType.NonAvailableType,
InterviewAvailability.Confirmed, InterviewAvailability.Other "
strSQL = strSQL & "FROM UserAccount INNER JOIN (NonAvailableType
INNER JOIN InterviewAvailability ON NonAvailableType.NonAvailableTypeID =
InterviewAvailability.UnavailableTypeID) ON UserAccount.UserAccountID =
InterviewAvailability.UserAccountID "
strSQL = strSQL & "WHERE InterviewAvailability.DOB = #" & mDOB & "#;"
 
Mark,

I think that it would be good to try to use in your class real datetime
values

Than this becomes

Dim objPerson as New clsPerson
objPerson.DOB = Cdate(txtDOB.text) ' or any other method of datetime
conversion

Just my thought,

Cor
 
We'll get this sooner or later... You said that you got this to work if
you put the textbox.text in there instead of the member variable. Do this
for me. After this line of code you just copied in here do this,
debug.writeline(strSQL). Then do the same for the version you got working.
Take a look at what the difference are. It has to be some kind of formating
that DOB has. What type of variable is DOB. Remember that in the textbox
it is a string. Try changing the DOB variable to a string and see if that
changes it. If it is, you may just need to format DOB with the .ToString
method (if DOB is a date that is).

Chris
 
Chris and Cor,

I have done that already. The CDate that is! When I run the page I get an
error Stating that: "Data Mismatch, String cannot be convert to a
Date"...werid?

Furthermore, Chris, I have this working (the SQL Statement) if I "hard code"
the Date Vaule in.

Any more ideas...? I am at a lost?

Mark
 
Mark,

You show non essential code. Essential is a part of your class, however you
even don't show what kind of database you use.

See what you can do with this sample I made some days ago. You need for that
to set the file (DataSource in the connect string) to a Nortwind access
database on your computer. Drag a datagrid and 2 textboxes on your form,
change the dates in row 3 an 4 to dates in your culture style and than start
debug.

\\\
TextBox1.Text = "20-07-1996"
TextBox2.Text = "31 juli 1996"
'Used is Dutch settings
Dim conn As New OleDb.OleDbConnection _
("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\test1\northwind.mdb")
Dim da As New OleDb.OleDbDataAdapter _
("SELECT * FROM Orders WHERE (OrderDate > ?) AND (OrderDate < ?)", conn)
da.SelectCommand.Parameters.Add _
(New OleDb.OleDbParameter("", OleDb.OleDbType.Date))
da.SelectCommand.Parameters.Add _
(New OleDb.OleDbParameter("", OleDb.OleDbType.Date))
da.SelectCommand.Parameters(0).Value = CDate(TextBox1.Text)
da.SelectCommand.Parameters(1).Value = CDate(TextBox2.Text)
Dim ds As New DataSet
da.Fill(ds)
DataGrid1.DataSource = ds.Tables(0)
///
I hope this helps a little bit?

Cor
 
Like I said before, we need to see the SQL that is being sent to the
database after it is loaded into the strSQL varirable. Do a
debug.writeline(strSQL) and show us what it is. This way we can see what
the format of mDOB looks like. That looks like where the problem is.

Chris
 
Back
Top