Write a program hw7 .sq1 that will insert a new customer record into the table,
ID: 3940841 • Letter: W
Question
Write a program hw7 .sq1 that will insert a new customer record into the table, like the following: The system skips 1 line and displays the New Customer Program title. The system prompts for social security number, last name, first name, middle name, and phone of the new customer. Notice that the user can enter in lower case. The system inserts the new record mto the CUSTOMERS table the system displays the new record (from the CUSTOMERS table) for confirmation. Note that the data should be displayed with appropriate format.Explanation / Answer
Answer:-
Step1 :- We can create database name Customer .
Step2:- We can cretae New Customer Table.
USE [Customer]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[New_Custome_Table](
[Id] [int] IDENTITY(1,1) NOT NULL,
[SSN_no] [char](9) NULL,
[LastName] [char](30) NULL,
[FirstName] [char](30) NULL,
[MiddleName] [char](30) NULL,
[Phone] [char](10) NULL,
CONSTRAINT [PK_New_Custome_Table] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
Step 3:- we can write html code.
<html>
<body>
<form >
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th colspan="3">
New Customer Registration
</th>
</tr>
<tr>
<td>
Social Security Number
</td>
<td>
<asp:TextBox ID="txtssno" runat="server" />
</td>
<td>
<asp:RequiredFieldValidator ErrorMessage="Required" ForeColor="Red" ControlToValidate="txtssno"
runat="server" />
</td>
</tr>
<tr>
<td>
LastName
</td>
<td>
<asp:TextBox ID="txtLastName" runat="server" />
</td>
<td>
<asp:RequiredFieldValidator ErrorMessage="Required" ForeColor="Red" ControlToValidate="LastName"
runat="server" />
</td>
</tr>
<tr>
<td>
FirstName
</td>
<td>
<asp:TextBox ID="txtFirstName" runat="server" />
</td>
<td>
<asp:RequiredFieldValidator ErrorMessage="Required" ForeColor="Red" ControlToValidate="FirstName"
runat="server" />
</td>
</tr>
<tr>
<td>
MiddleName
</td>
<td>
<asp:TextBox ID="txtMiddleName" runat="server" />
</td>
<td>
<asp:RequiredFieldValidator ErrorMessage="Required" ForeColor="Red" ControlToValidate="MiddleName"
runat="server" />
</td>
</tr>
<tr>
<td>
Phone No
</td>
<td>
<asp:TextBox ID="txtPhone" runat="server" />
</td>
<td>
<asp:RequiredFieldValidator ErrorMessage="Required" ForeColor="Red" ControlToValidate="Phone"
runat="server" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button Text="Submit" runat="server" />
</td>
<td>
</td>
</tr>
</table>
</form>
</body>
</html>
Step4 :- We can create connection string in web.config file
<connectionStrings>
<add name="Dbconnection" connectionString="server=servername;Integrated Security=false;Initial Catalog=Customer;user id= databaseuserid; password=password" />
</connectionStrings>
Step5:- we can create c# code in code behind page
use this all name spaces:
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
Step6:- we can create c# code in code behind page
private void RegisterNewUser_Click(object sender, EventArgs e)
{
string s = "insert into New_Custome_Table values('" + txtssno.Text + "','" + txtLastName.Text + "','" + txtFirstName.Text + "','" + txtMiddleName.Text + "','" + txtPhone.Text + "')";
SqlCommand cmd = new SqlCommand(s, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Customer Save Data Successfully.............!");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.