Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
6 views

_.NET lab

The document contains multiple C# programs that demonstrate various functionalities such as form handling, database operations, and XML data representation. Programs include input validation in a Windows Forms application, advertisement data in XML format, and web forms for displaying and managing employee details and login authentication. Each program showcases different aspects of .NET framework capabilities, including SQL database interactions and user interface elements.

Uploaded by

eyesfalls414
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

_.NET lab

The document contains multiple C# programs that demonstrate various functionalities such as form handling, database operations, and XML data representation. Programs include input validation in a Windows Forms application, advertisement data in XML format, and web forms for displaying and managing employee details and login authentication. Each program showcases different aspects of .NET framework capabilities, including SQL database interactions and user interface elements.

Uploaded by

eyesfalls414
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Program 6 :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace prog6
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void label3_Click(object sender, EventArgs e)


{

private void label1_Click(object sender, EventArgs e)


{

private void textBox1_TextChanged(object sender, EventArgs e)


{

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)


{
char ch = e.KeyChar;
if(char.IsDigit(ch))
{
MessageBox.Show("Enter the text ");
}
}

private void textBox2_KeyPress(object sender, KeyPressEventArgs e)


{
char ch = e.KeyChar;
if (char.IsLetter(ch))
{
MessageBox.Show("Enter the card number ");
}
}

private void button1_Click(object sender, EventArgs e)


{
if (textBox1.Text!="" && comboBox1.Text!=""&& textBox2.Text.Length
== 15)
{
MessageBox.Show("Valid Input");
}
else
{
MessageBox.Show("Invalid Input");
}
}
}
}
Program 7 :
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>dragon.jpg</ImageUrl>
<NavigateUrl>http://www.google.com</NavigateUrl>
<AlternateText>Order Flower,Roses,Gifts and
More...</AlternateText>
<Impressions>20</Impressions>
<Keywords>Flowers</Keywords>
</Ad>
<Ad>
<ImageUrl>panther.jpg</ImageUrl>
<NavigateUrl>http://www.google.com</NavigateUrl>
<AlternateText>Order Flower,Roses,Gifts and
More...</AlternateText>
<Impressions>20</Impressions>
<Keywords>Flowers</Keywords>
</Ad>
</Advertisements>
Program 8 :
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;

namespace ex8
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Timer1_Tick(object sender, EventArgs e)


{
SqlConnection Conn = new SqlConnection("Data Source=(LocalDB)\\
MSSQLLocalDB;AttachDbFilename=E:\\.NET\\ex8\\ex8\\App_Data\\
Database1.mdf;Integrated Security=True");
Conn.Open();
SqlCommand cmd = new SqlCommand("select * from crictd ", Conn);
SqlDataReader rd = cmd.ExecuteReader();
GridView1.DataSource = rd;
GridView1.DataBind();
Conn.Close();
}
}
}
Program 9 :
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;

namespace prgm9

{
public partial class WebForm1 : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source = (LocalDB)\\
MSSQLLocalDB; AttachDbFilename=C:\\Users\\Kongu Arts College\\source\\repos\\
prgm9\\prgm9\\App_Data\\Database1.mdf;Integrated Security = True");
protected void Page_Load(object sender, EventArgs e)
{
if(con.State==ConnectionState.Open)
{
con.Close();
}
con.Open();
disp_data();
}

protected void Button1_Click(object sender, EventArgs e)


{
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "insert into Employee_Details values('" +
TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "','" +
TextBox4.Text + "')";
cmd.ExecuteNonQuery();

TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
disp_data();
}

protected void Button2_Click(object sender, EventArgs e)


{
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "Update Employee_Details set Dept_name='" +
TextBox2.Text + "',Emp_name'" + TextBox3.Text + "',Salary'" + TextBox4.Text +
"'where Dept_id='" + TextBox1.Text + "' ";
cmd.ExecuteNonQuery();

TextBox1.Text = "";
TextBox2.Text = "";
TextBox3.Text = "";
TextBox4.Text = "";
disp_data();
}
protected void Button3_Click(object sender, EventArgs e)
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "delete from Employee_Details where Dept_id='" +
TextBox1.Text + "'";
cmd.ExecuteNonQuery();

TextBox1.Text = "";
disp_data();
}
public void disp_data()
{
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = " select * from Employee_Details";
cmd.ExecuteNonQuery();

DataTable dt = new DataTable();


SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs
e)
{

}
}
Program 10 :
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.Data.Sql;

namespace pg10.Properties
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

protected void Button1_Click(object sender, EventArgs e)


{
SqlConnection con = new SqlConnection("Data Source = (LocalDB)\\
MSSQLLocalDB; AttachDbFilename =C:\\Users\\Kongu Arts College\\source\\repos\\
pg10\\pg10\\App_Data\\Database1.mdf; Integrated Security = True");
SqlCommand cmd = new SqlCommand("select * from Login_Form where
USERNAME=@USERNAME and PASSWORD=@PASSWORD", con);
cmd.Parameters.AddWithValue("@USERNAME", TextBox1.Text);
cmd.Parameters.AddWithValue("@PASSWORD", TextBox2.Text);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
if (dt.Rows.Count > 0)
{
Response.Redirect("WebForm2.aspx");
}
else
{
Label1.Text = "Your Username and Password is Incorrect";
Label1.ForeColor = System.Drawing.Color.Red;
}
}
}
}

You might also like