Dear Sir,
I have a Textbox on my windows Form & I use that text to input date value.
My problem is how can I use this text box when I insert date into database.
sql = "Insert into Emp (DOB) values(????)
Pls guide me.
Thanks.
Printable View
Dear Sir,
I have a Textbox on my windows Form & I use that text to input date value.
My problem is how can I use this text box when I insert date into database.
sql = "Insert into Emp (DOB) values(????)
Pls guide me.
Thanks.
Generally you include the date value within single parenthesis i.e '01/01/01', but using parameter is more proper way to do that. You can find more info about parameter on MSDN or JMC's blog which i have linked in my signature
http://jmcilhinney.blogspot.com/
Sir in my form I have 2 textbox for EmpName and for DOB.. for Name I could enter simply but date if found difficulty.
This way ..
sql = "Insert into Emp (EmpName, DOB) values('" & textbox1.text & "',???????) for date how can convert text into date value.
Thanks a lot.
like the name part, the same way you should do for the dob.
You've already asked this question in another thread. Please keep each thread to a single topic and each topic to a single thread. If you were going to start a new thread for this then you shouldn;t have asked it in the other thread, which started with a different topic.
Anyway, first things first, the code you have posted in post #3 is not using parameters. Regardless of anything else, you are still using string concatenation to build your SQL, which is bad. Have you read the blog post of mine that both I (in that other thread) and aashish_9601 have recommended? If so then you know how to use parameters, so that's the first change you should make.
As for the date value, which has nothing specific to do with the data access code, you should probably be using a DateTimePicker rather than a TextBox. The DTP will handle both validation and conversion for you. All you have to do is get the Value property, which is type DateTime. In your case, you don't want the time portion, so you should get the Date property of that DateTime, which returns another DateTime with the same date and the time zeroed.
If you must use a TextBox then you can use the Date.TryParse method to validate and convert the String. Either way, you then assign the Date to parameter.
Your code is likely to get an error if the user enter an name like Ahmed's