Date Time Picker Help Needed

Status
Not open for further replies.

kulrom

Well-known member
Joined
May 10, 2005
Messages
2,854
Location
Republic of Macedonia
Programming Experience
10+
Current date:
VB.NET:
[SIZE=2][COLOR=#0000ff][COLOR=teal]'this is if you want to add date in format mm/dd/yy ..otherwise remove method toShortDateString[/COLOR]
Me[SIZE=2][COLOR=#000000].TextBox1.Text = [COLOR=blue]Date[/COLOR].[/COLOR][/SIZE][/COLOR][/SIZE]Now[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#000000].ToShortDateString [/COLOR][/SIZE]
[/COLOR][/SIZE]


Return Date:
VB.NET:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2][COLOR=#000000].TextBox1.Text = [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Date[/COLOR][/SIZE][SIZE=2][COLOR=#000000].Now.AddDays(3).ToShortDateString[/COLOR]
[/SIZE][/COLOR][/SIZE]

 

soppaln1

Member
Joined
Mar 28, 2006
Messages
13
Programming Experience
Beginner
hi i have got it to work, for some reason it is only adding the time into the database not the date, any ideas why?
 

soppaln1

Member
Joined
Mar 28, 2006
Messages
13
Programming Experience
Beginner
this is what it shows on my database, it caluclates the correct date on the form but shows the return date as 12.00am in my database.

database.jpg

i havent referenced the strReturndate string, when i assign it to the txtReturn text box, it gives me an object reader error.

any help would be appreciated.

kind regards
Sam
 

kulrom

Well-known member
Joined
May 10, 2005
Messages
2,854
Location
Republic of Macedonia
Programming Experience
10+
It is cuz you are doing wrong at least three things:
1st change the return time in design view to 'short date' instead long time as it is at the moment. you can also remove the default value of that field.
2nd change the order of assigment value to the varables. You are 1st passing values to the variables before you fulfill the fields with a dates so instead this:
VB.NET:
' Set strUsername and strPassword
strTransId = txtTransactionId.Text
strDate = DateTimePicker1.Text
strMediaId = txtMediaId.Text
strPaymentType = cmbPayment.Text
'strDate = txtDate.Text
 
'strReturnDate = txtReturn.Text
 
' strReturnDate = DateTimePicker1.Text
strPrice = txtPrice.Text
 
Me.txtReturn.Text = Date.Now.ToShortDateString
Me.txtReturn.Text = Date.Now.AddDays(3).ToShortDateString

make this:
VB.NET:
strTransId = txtTransactionId.Text
'strDate = DateTimePicker1.[B]Value[/B]
strMediaId = txtMediaId.Text
strPaymentType = cmbPayment.Text
strPrice = txtPrice.Text
 
Me.[B]txtDate[/B].Text = Date.Now.ToShortDateString
Me.txtReturn.Text = Date.Now.AddDays(3).ToShortDateString
 
strSQL = "INSERT INTO Transactions(Trans,Date1,MedId,Payment, ReturnDate, Pr) " & _
"VALUES ('" & strTransId & "', '" & [COLOR=blue]Me[/COLOR].[B]txtDate[/B].Text & "', '" & strMediaId & "' , " & _
"'" & strPaymentType & "' , '" & [I][COLOR=blue]Me[/COLOR].txtReturn.Text[/I] & "', '" & strPrice & "')"
Dim objCommand As New System.Data.OleDb.OleDbCommand(strSQL, objConnection)
 
objCommand.ExecuteNonQuery()

and 3rd remove that reader object as it is just annoying there. You do not use it at all (being declared and executed without real purpose) but rather execute comand as i did above:)

Regards ;)
 

soppaln1

Member
Joined
Mar 28, 2006
Messages
13
Programming Experience
Beginner
so your sayin use this code instead of what i had!

i tried it and it gave me an error at this line

objCommand.ExecuteNonQuery()

any ideas?

your code is more efficient.



' Set strUsername and strPassword
strTransId = txtTransactionId.Text
strDate = DateTimePicker1.Text
strMediaId = txtMediaId.Text
strPaymentType = cmbPayment.Text
'strDate = txtDate.Text

'strReturnDate = txtReturn.Text

' strReturnDate = DateTimePicker1.Text
strPrice = txtPrice.Text

Me.txtReturn.Text = Date.Now.ToShortDateString
Me.txtReturn.Text = Date.Now.AddDays(3).ToShortDateString


strTransId = txtTransactionId.Text
'strDate = DateTimePicker1.Value
strMediaId = txtMediaId.Text
strPaymentType = cmbPayment.Text
strPrice = txtPrice.Text

Me.txtDate.Text = Date.Now.ToShortDateString
Me.txtReturn.Text = Date.Now.AddDays(3).ToShortDateString

strSQL = "INSERT INTO Transactions(Trans,Date1,MedId,Payment, ReturnDate, Pr) " & _
"VALUES ('" & strTransId & "', '" & Me.txtDate.Text & "', '" & strMediaId & "' , " & _
"'" & strPaymentType & "' , '" & Me.txtReturn.Text & "', '" & strPrice & "')"
Dim objCommand As New System.Data.OleDb.OleDbCommand(strSQL, objConnection)

objCommand.ExecuteNonQuery()
 

soppaln1

Member
Joined
Mar 28, 2006
Messages
13
Programming Experience
Beginner
Hi KULROM

your an ace Man i got it to work just needed to rename the obj command, im a begginner at this language but had to learn lots quickly didnt do to badly i hope, i have another query mate if u dont mind as you answered this one with proficient code,

i would like to enter the detail in the form you have seen on a list box is it possible. whats the best way to do it im not really sure?


would it be somethin like this or am i totally wrong, basically im tryin to simulate a dvd rental system

evrytime a person add a dvd item it should be shown in the list box with all the column details from the database any ideas man.



heres the code

Dim objReader1 As System.Data.OleDb.OleDbDataReader




Dim objCommand1 As New System.Data.OleDb.OleDbCommand(strsql1, objConnection)

objReader1 = objCommand.ExecuteReader
strsql1 = ListBox1.Items.Add(objReader1.Item("Trans"))


objReader1.Close()
objReader1 = Nothing
objCommand1.Dispose()


is it wrong it doesnt seem to work lol

kind regards
Sam

ps-thank you very much for anwsering my previous query
 

kulrom

Well-known member
Joined
May 10, 2005
Messages
2,854
Location
Republic of Macedonia
Programming Experience
10+
What a Coincidence! I am working on same kind of application at the moment. Actually this is much advanced DVD rental system then peeps usually deal with but anyway that's it and i am almost done (I have a couple days yet).
Hmm ... if you have Yahoo IM contact me i'll be glad to help you about any particular question.
Regards ;)
 

soppaln1

Member
Joined
Mar 28, 2006
Messages
13
Programming Experience
Beginner
this guy is a genius.

looks perfect my friend, you have been very helpful.

thnakyou.

i will be posting some more questions.
 

soppaln1

Member
Joined
Mar 28, 2006
Messages
13
Programming Experience
Beginner
please delete my work...

hi kulrom

can you possibly delete this thread... or remove the attachment with my work, as i have completed the project.

cheers.
 
Status
Not open for further replies.
Top Bottom