private void bind()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("select * from employee1", con);
DataSet ds = new DataSet();
da.Fill(ds);
datalist1.DataSource = ds;
datalist1.DataBind();
}
protected void datalist1_ItemCommand(object source, DataListCommandEventArgs e)
{
}
protected void datalist1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Footer)
{
TextBox textid = e.Item.FindControl("textid") as TextBox;
TextBox textname = e.Item.FindControl("textname") as TextBox;
TextBox textaddress = e.Item.FindControl("textaddress") as TextBox;
TextBox texteducation = e.Item.FindControl("texteducation") as TextBox;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
SqlCommand cmd = new SqlCommand("Insert into employee1(emp_id,emp_name,emp_address,emp_education values(@1,@2,@3,@4)",con);
cmd.Parameters.Add("@1", SqlDbType.Int).Value = Convert.ToInt32(textid.Text);
cmd.Parameters.Add("@2", SqlDbType.NChar,10).Value = textname.Text;
cmd.Parameters.Add("@3", SqlDbType.NChar,10).Value = textaddress.Text;
cmd.Parameters.Add("@4", SqlDbType.NChar,10).Value=texteducation.Text;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
bind();
[Update]
Server Error in '/' Application.
Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.FormatException: Input string was not in a correct format.
Source Error:
Line 59: SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
Line 60: SqlCommand cmd = new SqlCommand("Insert into employee1(emp_id,emp_name,emp_address,emp_education values(@1,@2,@3,@4)",con);
Line 61: cmd.Parameters.Add("@1", SqlDbType.Int).Value = Convert.ToInt32("textid.Text");
Line 62: cmd.Parameters.Add("@2", SqlDbType.NChar,10).Value = textname.Text;
Line 63: cmd.Parameters.Add("@3", SqlDbType.NChar,10).Value = textaddress.Text;
Source File: C:\Users\Vishal\downloads\documents\visual studio 2010\Projects\WebApplication2\WebApplication2\datalist.aspx.cs Line: 61
Stack Trace:
[FormatException: Input string was not in a correct format.]
System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +11177559
System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +145
System.Convert.ToInt32(String value) +43
WebApplication2.WebForm1.datalist1_ItemDataBound(Object sender, DataListItemEventArgs e) in C:\Users\Vishal\downloads\documents\visual studio 2010\Projects\WebApplication2\WebApplication2\datalist.aspx.cs:61
System.Web.UI.WebControls.DataList.OnItemDataBound(DataListItemEventArgs e) +9579420
System.Web.UI.WebControls.DataList.CreateItem(Int32 itemIndex, ListItemType itemType, Boolean dataBind, Object dataItem) +151
System.Web.UI.WebControls.DataList.CreateControlHierarchy(Boolean useDataSource) +9580357
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e) +63
System.Web.UI.WebControls.BaseDataList.DataBind() +54
WebApplication2.WebForm1.bind() in C:\Users\Vishal\downloads\documents\visual studio 2010\Projects\WebApplication2\WebApplication2\datalist.aspx.cs:39
WebApplication2.WebForm1.Page_Load(Object sender, EventArgs e) in C:\Users\Vishal\downloads\documents\visual studio 2010\Projects\WebApplication2\WebApplication2\datalist.aspx.cs:19
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +92
System.Web.UI.Control.LoadRecursive() +54
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772