Q12.
Create a web application Login Module which adds Usemame and Password in the
database. Usemame in the database should be a primary key.
Solution:
Step 1: Create a database file with following fields: UserName, Password, UserName with
primary key attributes.
Step 2: Design the web page as:
Step3: Do the following Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
System.Data.SqlClient.SqlConnection conn = new
System.Data.SqlClient.SqlConnection("Data Source=.;Initial Catalog=dd;Integrated
Security=True");
protected void Button1_Click(object sender, EventArgs e)
{
System.Data.SqlClient.SqlCommand comm = new
System.Data.SqlClient.SqlCommand("insert into d values('" + TextBox1.Text + "',
'" + TextBox2.Text + "')", conn);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
}
}
Q 13 Create a web application to insert 3 records inside the SQL database table having
following fields( Deptld, DeptName, EmpName, Salary). Update the salary for any one
employee and increment it to 15% of the present salary. Perform delete operation on
1 row of the database table.
Solution:
Step 1: Create a dept table with the following field in a database : DeptId, DeptName,
EmpName, Salary
Step 2: Inset some records inside of it.
Step 3: Design the following interface in the visual studio.
Step 4: Do the coding for the designed interface.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
System.Data.SqlClient.SqlConnection conn = new
System.Data.SqlClient.SqlConnection("Data Source=.;Initial Catalog=dd;Integrated
Security=True");
protected void Page_Load(object sender, EventArgs e)
{
System.Data.SqlClient.SqlDataAdapter ad = new
System.Data.SqlClient.SqlDataAdapter("select * from dept", conn);
System.Data.DataTable dt = new System.Data.DataTable();
ad.Fill(dt);
DropDownList1.DataSource = dt;
// DropDownList1.DataTextField = dt.Columns["DeptName"].ToString();
// DropDownList1.DataValueField = dt.Columns["DeptId"].ToString();
DropDownList1.DataMember = dt.Columns["DeptName"].ToString();
DropDownList1.DataValueField = dt.Columns["DeptId"].ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
System.Data.SqlClient.SqlCommand comm = new
System.Data.SqlClient.SqlCommand("updat table dept set Empname = '" +
TextBox1.Text + "', Salary = " + Convert.ToInt16(TextBox2.Text)
+Convert.ToInt16(TextBox2.Text)*.15 +" where Deptid = "
+DropDownList1.SelectedValue , conn);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
System.Data.SqlClient.SqlCommand comm = new
System.Data.SqlClient.SqlCommand("Delete *from table = dept where Deptid = " +
DropDownList1.SelectedValue, conn);
conn.Open();
comm.ExecuteNonQuery();
conn.Close();
}
}
Step 5: Now execute the program.