This document provides code for a C# library management program that uses ADO.NET and SQL Server. The program allows users to insert, delete, update, and view data in a library database. It includes code to connect to the database, insert book issue and return records, update return dates, and display data in a datagridview. The code is organized into methods that are triggered by button clicks to perform the different operations on the library database.
1. PROGRAMMING USING C#
LAB MANUAL
SARASWATHI RAMALINGAM
SRI AKILANDESWARI WOMENS COLLEGE
THIRUVALLUVAR UNIVERSITY
2. ADO.NET-LIBRARY MANAGEMENT[DB SQL SERVER]
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;
using System.Data.SqlClient;
namespace ADO.NETCONNECTION
{
public partial class Form1 : Form
{
string connectionstring = @"Data Source=CLIENT1-PC;Initial Catalog=SARAS;Integrated
Security=True";
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectionstring);
con.Open();
SqlCommand cmd = new SqlCommand("INSERT INTO library
VALUES('"+textBox1.Text+"','"+textBox2.Text+"','"+textBox3.Text+"','"+textBox4.Text+"')",con);
3. try
{
cmd.ExecuteNonQuery();
MessageBox.Show("BOOK ISSUED");
}
catch (Exception)
{
MessageBox.Show("BOOK NOT ISSUED");
}
finally
{
con.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectionstring);
con.Open();
SqlCommand cmd = new SqlCommand("DELETE FROM library WHERE
LIBRARYID='"+textBox1.Text+"'",con);
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("BOOK RETURNED");
}
catch (Exception)
{
MessageBox.Show("BOOK NOT RETURN");
}
finally
{
con.Close();
}
}
4. private void button4_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectionstring);
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM library", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
cmd.ExecuteNonQuery();
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
con.Close();
}
private void button3_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connectionstring);
con.Open();
SqlCommand cmd = new SqlCommand("UPDATE library SET
RETURNDATE='" + textBox4.Text + "'", con);
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("DATE EXTENDED");
}