I want to know how to insert a datetime value from asp.net using a calender control using C#. ? I have a Calender control and a button . When i click the button the date should be inserted into an sql server table which has a date column of the type datetype.
First of all i dont have much knowledge about stored procedures.Secondly, why cant we use the same principle used to insert a textbox value into a SQL database?
Forget whatever i have asked . I will tell you my requirement . I have a registration page (as part of my college project (online library management system)) . In the registration page there is an option to enter the date of birth . I tried to use
the calender control . But now i realized that if i was born in june 1975 i should click all the way back from april 2012. Also the ADO code written with procedures is not in my league(Unless some one can make it simpler)
.
1) What are the othe alternatives for entering the date of birth in a registration form?
Another problem . Since the datatype of the date of birth is datetime in sql server and the three values combined is a string , i need to cast them into datetime type and i dont know how?|
achuthan1988
Member
53 Points
159 Posts
how to insert datetime value into SQL from ASP.NET using calender control?
Apr 30, 2012 06:52 AM|LINK
I want to know how to insert a datetime value from asp.net using a calender control using C#. ? I have a Calender control and a button . When i click the button the date should be inserted into an sql server table which has a date column of the type datetype.
ManojNR
Member
114 Points
59 Posts
Re: how to insert datetime value into SQL from ASP.NET using calender control?
Apr 30, 2012 07:26 AM|LINK
Have u written stored procedure to perform Insert ? If yes post it here.
achuthan1988
Member
53 Points
159 Posts
Re: how to insert datetime value into SQL from ASP.NET using calender control?
Apr 30, 2012 07:35 AM|LINK
No i havent . I know how to insert a textbox value using ADO.NET .Cant the same principle be applied to a calendar control?
prashantdigh...
Member
101 Points
56 Posts
Re: how to insert datetime value into SQL from ASP.NET using calender control?
Apr 30, 2012 07:43 AM|LINK
con.Open() cmd.Connection = con cmd.CommandType = CommandType.StoredProcedure cmd.CommandText = "STOREDPROCEDURENAME" cmd.Parameters.Add("@PARAMETERNAME1", SqlDbType.NVarChar).Value = Calendar1.SelectedDate.ToString("dd/MM/yyyy")cmd.ExecuteNonQuery() con.Close()Hope this will help u a lot!!!!!!!!!!
ramiramilu
All-Star
95275 Points
14072 Posts
Re: how to insert datetime value into SQL from ASP.NET using calender control?
Apr 30, 2012 08:32 AM|LINK
using (SqlCommand cmd = new SqlCommand("insert into TableName(Idate) values(@adate"),new SqlConnection("Your conn str here")) { cmd.Parameters.AddWithValue("@adate",Calendar.SelectedDate.ToString("yyyy/MM/dd")); cmd.Connection.Open(); cmd.ExecuteNonQuery(); }JumpStart
achuthan1988
Member
53 Points
159 Posts
Re: how to insert datetime value into SQL from ASP.NET using calender control?
Apr 30, 2012 09:01 AM|LINK
First of all i dont have much knowledge about stored procedures.Secondly, why cant we use the same principle used to insert a textbox value into a SQL database?
achuthan1988
Member
53 Points
159 Posts
Re: how to insert datetime value into SQL from ASP.NET using calender control?
Apr 30, 2012 09:13 AM|LINK
Forget whatever i have asked . I will tell you my requirement . I have a registration page (as part of my college project (online library management system)) . In the registration page there is an option to enter the date of birth . I tried to use the calender control . But now i realized that if i was born in june 1975 i should click all the way back from april 2012. Also the ADO code written with procedures is not in my league(Unless some one can make it simpler) .
1) What are the othe alternatives for entering the date of birth in a registration form?
Siddu_shivpu...
Member
93 Points
68 Posts
Re: how to insert datetime value into SQL from ASP.NET using calender control?
Apr 30, 2012 09:18 AM|LINK
better to use 3 dropdownlist one for day, month, year.....
may be this suitable for u r req.....
and about storing date in database just combine these 3 dropdownlist in watever dateformate u want.... and store in database...
Thank You........
achuthan1988
Member
53 Points
159 Posts
Re: how to insert datetime value into SQL from ASP.NET using calender control?
Apr 30, 2012 09:26 AM|LINK
i thought about using three drop downs .
So should i combine these 3 values into a single value like(yyyy/mm/dd) and then insert it into the respective column?
achuthan1988
Member
53 Points
159 Posts
Re: how to insert datetime value into SQL from ASP.NET using calender control?
Apr 30, 2012 10:15 AM|LINK
Another problem . Since the datatype of the date of birth is datetime in sql server and the three values combined is a string , i need to cast them into datetime type and i dont know how?|