private SqlDataCon SCon = new SqlDataCon();
private SqlDataReader Dr;
insert code as follows;
protected void Button1_Click(object sender, EventArgs e)
{
Label6.Text = "";
if (FromDate.SelectedDateValue.ToString() == "")
{
Label6.Text = "From date is not selected";
return;
}
if (Todate.SelectedDateValue.ToString() == "")
{
Label6.Text = "To date is not selected";
return;
}
Sql = "insert into BirthDayWish values('" + txt_name.Text + "','" + FromDate.SelectedDateValue.ToString() + "','" + txt_mobile.Text + "','" + Todate.SelectedDateValue.ToString() + "','a','" + txt_Email.Text + "')";
try
{
Dr = SCon.ReadSql(Sql);
//GridView1.DataSource = Dr;
//GridView1.DataBind();
Dr.Close();
}
catch (Exception Ex1)
{
Response.Write(Ex1);
}
} but is not saving in the database why>
Satyapriya NayakPosted Dec 25, 2012, 7:19 AM
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace WebApplication11
{
public partial class WebForm1 : System.Web.UI.Page
{
string strConnString = ConfigurationManager.ConnectionStrings["MyConsString"].ConnectionString;
string str;
SqlCommand cmd;
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = "insert into BirthDayWish values('" + txt_name.Text + "','" + FromDate.SelectedDate.ToString("dd/MM/yyyy") + "','" + txt_mobile.Text + "','" + Todate.SelectedDate.ToString("dd/MM/yyyy") + "','a','" + txt_Email.Text + "')";
cmd = new SqlCommand(str,con);
cmd.ExecuteNonQuery();
con.Close();
}
}
}