0% found this document useful (0 votes)
25 views2 pages

CODE

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views2 pages

CODE

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, 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.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication6
{
public partial class Form1 : Form
{
static string conString = "Data Source=(LocalDB)\\
MSSQLLocalDB;AttachDbFilename=c:\\users\\student.desktop-05rcfoa.000\\documents\\
visual studio 2015\\Projects\\WindowsFormsApplication6\\WindowsFormsApplication6\\
Database1.mdf;Integrated Security=True";
SqlConnection con = new SqlConnection(conString);

public Form1()
{
InitializeComponent();
}

private void listBox2_SelectedIndexChanged(object sender, EventArgs e)


{

private void button1_Click(object sender, EventArgs e)


{
con.Open();
SqlCommand cmd = new SqlCommand("select * from table1",con);
SqlDataReader reader = cmd.ExecuteReader();

listBox1.Items.Clear();
listBox2.Items.Clear();
listBox3.Items.Clear();

while (reader.Read())
{
listBox1.Items.Add(reader[0]);
listBox2.Items.Add(reader[1]);
listBox3.Items.Add(reader[2]);
}
con.Close();
}

private void button2_Click(object sender, EventArgs e)


{
con.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO table1 VALUES(@RN,@N,@M)",
con);
cmd.Parameters.AddWithValue("@RN", Int32.Parse(textBox1.Text));
cmd.Parameters.AddWithValue("@N", textBox2.Text);
cmd.Parameters.AddWithValue("@M", Int32.Parse(textBox3.Text));
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Record inserted");
}

private void button3_Click(object sender, EventArgs e)


{
con.Open();
SqlCommand cmd = new SqlCommand("UPDATE table1 SET RNO=@RN, STNAME=@N,
MARKS=@M WHERE RNO=@RN", con);
cmd.Parameters.AddWithValue("@RN", Int32.Parse(textBox1.Text));
cmd.Parameters.AddWithValue("@N", textBox2.Text);
cmd.Parameters.AddWithValue("@M", Int32.Parse(textBox3.Text));
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Record uPDATED");
}

private void button4_Click(object sender, EventArgs e)


{
con.Open();
SqlCommand cmd = new SqlCommand("DELETE FROM table1 WHERE RNO=@RN",
con);
cmd.Parameters.AddWithValue("@RN", Int32.Parse(textBox1.Text));
//cmd.Parameters.AddWithValue("@N", textBox2.Text);
//cmd.Parameters.AddWithValue("@M", Int32.Parse(textBox3.Text));
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Record dELETED");
}
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy