Click here to Skip to main content
15,843,727 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
Hi,

I have a column with date datatype in my DB. from a website, i am using a calendar control (using ajax) and i need to bind the value of the selected calendar to a variable of type date and then store it in db.

I am using the following code in html and in my .vb page but getting exceptions everytime.

Please help me:
<b>
<u>html page:</u></b>

 <asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtbx_req_prod_date" Format="MM/dd/yyyy"></asp:CalendarExtender>
<asp:TextBox ID="txtbx_req_prod_date" runat="server"></asp:TextBox>

<b><u>vb page:</u></b>

Dim Req_prod_date As Date
txtbx_req_prod_date.Text = CalendarExtender1.SelectedDate.ToString()
Req_prod_date = txtbx_req_prod_date.ToString()

Qry = "Insert into myshemaname.mytablename" & _
              "(column_name)" & _
              "values ('" & Req_prod_date & "')"

then i use command.executenonquery and stuffs to insert this.....


Thanks in advance
Posted
Comments
[no name] 4-Aug-13 6:31am    
1. You did not tell us what the exceptions are.
2. Do not use string concatenation to construct SQL. Use parameterized queries.
3. Calling ToString on something that is already a string is completely useless.
4. Your actual problem is that you are trying to assign a string to a DateTime. You would need to use DateTime.Parse or TryParse. Why you are doing that at all is a mystery since it is a DateTime to begin with.
Sai Janani 4-Aug-13 7:17am    
Hi,
Thanks for the response. I am tring to bind the value of selected date from calendar control to a column inside my database.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900