BankInfo.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BankInfo.aspx.cs"
Inherits="_7C.BankInfo" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 100%;
}
.auto-style2 {
width: 136px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="auto-style1">
<tr>
<td class="auto-style2">
<asp:Label ID="LabelAddress" runat="server" Text="Bank
Address"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="LabelCity" runat="server" Text="Bank City"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="Labelname" runat="server" Text="Bank Branch
Name"></asp:Label>
</td> <td>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="LabelState" runat="server" Text="State"></asp:Label>
</td> <td>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Label ID="LabelZip" runat="server" Text="Zip Code"></asp:Label>
</td> <td>
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td> </td>
</tr>
<tr>
<td class="auto-style2"> </td>
<td>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Insert" Width="83px" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click"
Text="Delete" Width="90px" />
</td>
</tr>
</table>
</div>
<asp:Label ID="Label1" runat="server" Text=" "></asp:Label>
</form>
</body>
</html>
BankInfo.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace _7C
{
public partial class BankInfo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string connStr =
ConfigurationManager.ConnectionStrings["connStrs"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
string InsertQuery = "insert into Bank values(@ADDRESS, @CITY, @NAME,
@STATE, @ZIP_CODE)";
SqlCommand cmd = new SqlCommand(InsertQuery, con); cmd.Parameters.AddWithValue("@ADDRESS", TextBox1.Text); cmd.Parameters.AddWithValue("@CITY", TextBox2.Text); cmd.Parameters.AddWithValue("@NAME", TextBox3.Text); cmd.Parameters.AddWithValue("@STATE", TextBox4.Text);
cmd.Parameters.AddWithValue("@ZIP_CODE", TextBox5.Text);
con.Open();
cmd.ExecuteNonQuery();
Label1.Text = "Record Inserted Successfuly.";
con.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
string connStr =
ConfigurationManager.ConnectionStrings["connStrs"].ConnectionString;
SqlConnection con = new SqlConnection(connStr);
string InsertQuery = "delete from bank where NAME=@NAME";
SqlCommand cmd = new SqlCommand(InsertQuery, con);
cmd.Parameters.AddWithValue("@NAME", TextBox1.Text);
con.Open();
cmd.ExecuteNonQuery();
Label1.Text = "Record Deleted Successfuly.";
con.Close();
}
}
}
Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.7.2"/>
<httpRuntime targetFramework="4.7.2"/>
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:41008
/define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers>
</system.codedom>
<connectionStrings>
<add name="connStr" connectionString="Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename='C:\Users\tushars\Documents\Visual Studio 2015\WebSites\Workshop\App_Data\Database.mdf';Integrated Security=True" providerName="System.Data.SqlClient" /> <add name="connStrs" connectionString="Data
Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\RupamSolution\source\repos
\7C\7C\App_Data\BankDetails.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
0 Comments