0% found this document useful (0 votes)
32 views

Using Using Using Using Using Using Using Using Namespace Public Partial Class Public

The document defines a Windows form with labels and text boxes for entering a student's name, father's name, CNIC, address, and contact. Buttons are added to save or clear the entered data. When the save button is clicked, a SQL connection is opened and an INSERT query is executed to add the student data to a database table. An update and delete query are also provided.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Using Using Using Using Using Using Using Using Namespace Public Partial Class Public

The document defines a Windows form with labels and text boxes for entering a student's name, father's name, CNIC, address, and contact. Buttons are added to save or clear the entered data. When the save button is clicked, a SQL connection is opened and an INSERT query is executed to add the student data to a database table. An update and delete query are also provided.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

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

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

private void Form1_Load(object sender, EventArgs e)


{
Label l1=new label();
L1.Text=Name :;
L1.Size(100,100);
L2.Text=Father name :;
L2.Size(100,100);

L3.Text=CNIC :;
L3.Size(100,100);

L4.Text=Address :;
L4.Size(100,100);

L5.Text=Contact :;
L5.Size(100,100);
Form1.Controls.Add(l1);
Form1.Controls.Add(l2);
Form1.Controls.Add(l3);
Form1.Controls.Add(l4);
Form1.Controls.Add(l5);
TextBox t1=new TextBox();
TextBox t2=new TextBox();
TextBox t3=new TextBox();
TextBox t4=new TextBox();
TextBox t5=new TextBox();
Form1.Controls.Add(t1);
Form1.Controls.Add(t2);
Form1.Controls.Add(t3);
Form1.Controls.Add(t5);
Form1.Controls.Add(t6);

Button b1=new Button();


b1.Text=save;
Button b2=new Button();
b2.Text=clear;
Form1.Controls.Add(b1);
Form1.Controls.Add(b2);
private void b1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Integrated Security=true; Initial Catalog=std; Data Source
= 'SHAHZAD-PC\\SQLEXPRESS'";

SqlCommand com = new SqlCommand();


com.Connection = con;
com.CommandText = "INSERT INTO student values
("+t1.Text+",'"+t2.Text.Trim()+"','"+t3.Text.Trim()+"','"+t4.Text.Trim()+"'+t5.Text.Trim()+"')
";

try
{
con.Open();
com.ExecuteNonQuery();
MessageBox.Show("Record is saved in specified database");

}catch(Exception){}

private void b2_Click(object sender, EventArgs e)


{
t1.Text = "";
t2.Text = "";
t3.Text = "";
t4.Text = "";
t5.Text = "";

}}}}}
Editional query

Delete

com.CommandText = "Delete student where id=txt1";

update
com.CommandText = "update student set name=txtname where id=txtid";

You might also like