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);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Configuration;
public partial class test4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private void ExecuteInsert(string Username, string Password, DateTime Startdate)
{
string connectionString = ConfigurationManager.ConnectionStrings["SQLDbConnection"].ToString();
SqlConnection con = new SqlConnection(connectionString);
string sql = "INSERT INTO first (Username, Password, Startdate) VALUES" + "(@Username,@Password,Startdate)";
try
{
con.Open();
SqlCommand cmd = new SqlCommand(sql, con);
SqlParameter[] param = new SqlParameter[3];
param[0] = new SqlParameter("@Username", SqlDbType.VarChar, 50);
param[1] = new SqlParameter("@Password", SqlDbType.VarChar, 50);
param[2] = new SqlParameter("@Startdate", SqlDbType.DateTime);
param[0].Value = Username;
param[1].Value = Password;
param[2].Value = Startdate;
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param);
}
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
con.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
// DateTime date = DateTime.ParseExact(TextBox3.Text.ToString(),"",null);
// DateTime date = Convert.ToDateTime(TextBox3_CalendarExtender.SelectedDate);
ExecuteInsert(TextBox1.Text, TextBox2.Text, date;
Response.Write("Record was successfully added!");
}

New Topic/Question
Reply



MultiQuote



|