473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to store date of ajax calender extender from asp.net to sql server

hiii

how to store the date of ajax calender extender from textbox to database(sql server 2005).

how to pass the date inthe following statement
ExecuteInsert(TextBox1.Text, TextBox2.Text, date);



Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.Data;
  8. using System.Data.Sql;
  9. using System.Data.SqlClient;
  10. using System.Configuration;
  11.  
  12. public partial class test4 : System.Web.UI.Page
  13. {
  14.     protected void Page_Load(object sender, EventArgs e)
  15.     {
  16.  
  17.     }
  18.     private void ExecuteInsert(string Username, string Password, DateTime Startdate)
  19.     {
  20.         string connectionString = ConfigurationManager.ConnectionStrings["SQLDbConnection"].ToString();
  21.         SqlConnection con = new SqlConnection(connectionString);
  22.         string sql = "INSERT INTO first (Username, Password, Startdate) VALUES" + "(@Username,@Password,Startdate)";
  23.  
  24.         try
  25.         {
  26.             con.Open();
  27.             SqlCommand cmd = new SqlCommand(sql, con);
  28.             SqlParameter[] param = new SqlParameter[3];
  29.             param[0] = new SqlParameter("@Username", SqlDbType.VarChar, 50);
  30.             param[1] = new SqlParameter("@Password", SqlDbType.VarChar, 50);
  31.             param[2] = new SqlParameter("@Startdate", SqlDbType.DateTime);
  32.  
  33.             param[0].Value = Username;
  34.             param[1].Value = Password;
  35.             param[2].Value = Startdate;
  36.  
  37.             for (int i = 0; i < param.Length; i++)
  38.             {
  39.                 cmd.Parameters.Add(param[i]);
  40.             }
  41.             cmd.CommandType = CommandType.Text;
  42.             cmd.ExecuteNonQuery();
  43.  
  44.         }
  45.         catch (System.Data.SqlClient.SqlException ex)
  46.         {
  47.             string msg = "Insert Error:";
  48.             msg += ex.Message;
  49.             throw new Exception(msg);
  50.         }
  51.         finally
  52.         {
  53.             con.Close();
  54.         }
  55.  
  56.     }
  57.  
  58.     protected void Button1_Click(object sender, EventArgs e)
  59.     {
  60.  
  61.        // DateTime date = DateTime.ParseExact(TextBox3.Text.ToString(),"",null);
  62.        // DateTime date = Convert.ToDateTime(TextBox3_CalendarExtender.SelectedDate);
  63.         ExecuteInsert(TextBox1.Text, TextBox2.Text, date);
  64.         Response.Write("Record was successfully added!");
  65.  
  66.     }
Aug 30 '12 #1
1 8957
Parse the textbox string into datetime, using below line and pass it to SQL server. If your date format is change from below thing, change it accordingly.
DateTime Startdate= DateTime.ParseExact(txtfromdate.Text, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture) ;

Thank you
Aug 30 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Nina via DBMonster.com | last post by:
Hi, I am trying to use the AIV extender with DB2 PE v 8.2. However, when i try to enable database for DB2Video I get the following error report: db2ext => enable database for db2video...
1
by: William Youngman | last post by:
I have a gridview displaying data and would like to use the AJAX dropdown extender so that when the user clicks on a record a dropdown menu will display providing the user with a menu of selections...
4
by: BillE | last post by:
Can I make the Ajax calendar extender appear on top of dropdown lists instead of behind them? Thanks Bill
0
by: jitendar | last post by:
Hii all, Anyone tell me "How to parse html file and store its contents in sql server 2005 in asp.net C#" Thanks and regards Jitendar talwar Mailto: jiten.talwar007@gmail.com
1
by: shaileshb | last post by:
hi all, I want to convert PDF document to XML or HTML and store converted data into SQL Server, pls let me know the process and if possible code for this using vb.net or C#
6
by: shahoo | last post by:
Hi, I know this is not a good place for this post, but I have too. I need to store Hijri Date in SQL Server 2005, but because it is year 1386 in Hijri calendar, SQL Server does not let me do that....
2
by: taufik | last post by:
Hi, I have problem with my simple program. Actually, I try to store date value in form of date format (mm/dd/yyyy). I got message that inform me "number of query values and destination fields are...
2
by: =?Utf-8?B?QWJoaWxhc2g=?= | last post by:
Hi, I am using AJAX calendar extender.Everything is works fine on date selection from pop up image option but when i dont select a date and click outside on the page,calender remains poped up,it...
1
by: bellgodz | last post by:
Hello, I have a text box on an .aspx page that an AJAX calendar extender is tied to. When this page is loaded the text box in question is populated with a date from a selected record. I've tried...
21
Vkas
by: Vkas | last post by:
i had created my own web calender control!!!! it consist 1} text box (it display's the selected date) 2} button (it hide and show the calender control) 3} calender control (use for the selection...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.