I have tried to do a test to a lesson which was in the internet, but it doesn't work?
ANYBody here to help please??
The problem that what I enter in the textbox should be sent to the database to be stored, but it doesn't.!!! I don't know why
the aspx. page...
Expand|Select|Wrap|Line Numbers
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head id="Head1" runat="server">
- <title>Untitled Page</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <asp:Panel runat ="server" ID="panel1">
- <asp:label ID="label1" runat="server" Font-Size="XX-Large">Data Entry Form</asp:label><br /><br />
- Sno : <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /><br />
- Name : <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox><br /><br />
- Age : <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox><br /><br />
- Salary<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox><br /><br />
- <asp:Button ID="Button1" runat="server" Text="Insert Record" />
- </asp:Panel>
- </div>
- </form>
- </body>
- </html>
the aspx.cs file code
Expand|Select|Wrap|Line Numbers
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- public partial class Default4 : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- SqlDataAdapter da = new SqlDataAdapter("Select * from Emp", "Server=localhost; database=CV; integrated security=true;");
- SqlCommandBuilder cb = new SqlCommandBuilder(da);
- DataSet ds = new DataSet();
- da.FillSchema(ds, SchemaType.Source);
- DataRow dr = ds.Tables[0].NewRow();
- dr[0] = int.Parse(TextBox1.Text);
- dr[1] = TextBox2.Text;
- dr[2] = int.Parse(TextBox3.Text);
- dr[3] = double.Parse(TextBox4.Text);
- ds.Tables[0].Rows.Add(dr);
- try
- {
- da.Update(ds);
- }
- catch (Exception ex)
- {
- Response.Write(ex.Message);
- return;
- }
- Response.Write("Record Added.");
- }
- }
and I have a database with
"Emp" as table name
"Sno" as int type
"Name" as varchar(50) type
"Age" as int type
"Salary" as money type