<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.style1{width: 400px;}
.style1 td {width:200px;}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:Literal ID="LiteralMessage" runat="server"></asp:Literal>
<table class="style1">
<tr>
<td>Company ID</td>
<td><asp:TextBox ID="TextBoxID" runat="server"/></td>
</tr>
<tr>
<td>Company Name</td>
<td><asp:TextBox ID="TextBoxCompanyName" runat="server"/></td>
</tr>
<tr>
<td>Contact Name</td>
<td><asp:TextBox ID="TextBoxContactName" runat="server"/></td>
</tr>
<tr>
<td>Contact Title</td>
<td><asp:TextBox ID="TextBoxContactTitle" runat="server"/></td>
</tr>
<tr>
<td>Address</td>
<td><asp:TextBox ID="TextBoxAddress" runat="server"/></td>
</tr>
<tr>
<td>City</td>
<td><asp:TextBox ID="TextBoxCity" runat="server"/></td>
</tr>
<tr>
<td>Region</td>
<td><asp:TextBox ID="TextBoxRegion" runat="server"/></td>
</tr>
<tr>
<td>Postal Code</td>
<td><asp:TextBox ID="TextBoxPostalCode" runat="server"/></td>
</tr>
<tr>
<td>Country</td>
<td><asp:TextBox ID="TextBoxCountry" runat="server"/></td>
</tr>
</table>
<asp:Button ID="Button1" runat="server" Text="Save" onclick="Button1_Click" />
</form>
</body>
</html>
|
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Xml.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SaveCustomerInfo();
}
private void SaveCustomerInfo()
{
using (NorthwindDataContext context = new NorthwindDataContext())
{
//Create a new instance of the Customer object
Customer cust = new Customer();
//Add new values to each fields
cust.CustomerID = TextBoxID.Text;
cust.CompanyName = TextBoxCompanyName.Text;
cust.ContactName = TextBoxContactName.Text;
cust.ContactTitle = TextBoxContactTitle.Text;
cust.Address = TextBoxAddress.Text;
cust.City = TextBoxCity.Text;
cust.Region = TextBoxRegion.Text;
cust.PostalCode = TextBoxPostalCode.Text;
cust.Country = TextBoxCountry.Text;
//Insert the new Customer object
context.Customers.InsertOnSubmit(cust);
//Sumbit changes to the database
context.SubmitChanges();
//Display Message for successful operation
LiteralMessage.Text = "<p style='color:Green;'>Information Successfully saved!</p>";
}
}
}
|








