The System.Data.SqlClient namespace in C# is used to enable database connectivity and interaction using SQL Server. This allows applications to communicate directly with Microsoft SQL Server for executing queries, retrieving data, and managing transactions efficiently.
SQL Server Client
SqlClient is a Microsoft technology designed to provide a seamless way of accessing SQL Server databases. It offers optimized performance, secure connections, and direct execution of SQL commands for efficient data management.
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; // SQL Server Database Connectivity namespace SqlConect { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { // Load Data into DataGridView this.detailsTableAdapter.Fill(this.firstSQLDataSet.Details); } private void btnInsert_Click(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand(); SqlConnection con = new SqlConnection(); cmd.Connection = con; con.ConnectionString = @"Data Source=DESKTOP-73VBH0K\SQLEXPRESS;Initial Catalog=FirstSQL;Integrated Security=True"; con.Open(); cmd.CommandText = "Insert Into [Table_Name] Values (" + textBox1.Text + ",'" + textBox2.Text + "','" + textBox3.Text + "'," + textBox4.Text + ")"; cmd.ExecuteNonQuery(); MessageBox.Show("✅ Record Inserted Successfully!"); } private void btnUpdate_Click(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand(); SqlConnection con = new SqlConnection(); cmd.Connection = con; con.ConnectionString = @"Data Source=DESKTOP-73VBH0K\SQLEXPRESS;Initial Catalog=FirstSQL;Integrated Security=True"; con.Open(); cmd.CommandText = "Update [Table_Name] Set Student_Course = '" + textBox3.Text + "' Where Student_ID =" + textBox1.Text + " "; cmd.ExecuteNonQuery(); MessageBox.Show("✅ Record Updated Successfully!"); } private void btnDelete_Click(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand(); SqlConnection con = new SqlConnection(); cmd.Connection = con; con.ConnectionString = @"Data Source=DESKTOP-73VBH0K\SQLEXPRESS;Initial Catalog=FirstSQL;Integrated Security=True"; con.Open(); cmd.CommandText = "Delete From [Table_Name] Where Student_ID =" + textBox1.Text + " "; cmd.ExecuteNonQuery(); MessageBox.Show("🗑️ Record Deleted!"); } private void btnSearch_Click(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand(); SqlConnection con = new SqlConnection(); cmd.Connection = con; con.ConnectionString = @"Data Source=DESKTOP-73VBH0K\SQLEXPRESS;Initial Catalog=FirstSQL;Integrated Security=True"; con.Open(); cmd.CommandText = "Select * From [Table_Name] Where Student_ID =" + textBox1.Text + " "; SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { textBox1.Text = dr[0].ToString(); textBox2.Text = dr[1].ToString(); textBox3.Text = dr[2].ToString(); textBox4.Text = dr[3].ToString(); } MessageBox.Show("🔍 Record Found!"); } private void txtSearch_TextChanged(object sender, EventArgs e) { SqlCommand cmd = new SqlCommand(); SqlConnection con = new SqlConnection(); cmd.Connection = con; con.ConnectionString = @"Data Source=DESKTOP-73VBH0K\SQLEXPRESS;Initial Catalog=FirstSQL;Integrated Security=True"; con.Open(); cmd.CommandText = "Select * From [Table_Name] Where Student_Name Like '%" + textBox5.Text + "%'"; SqlDataReader dr = cmd.ExecuteReader(); DataTable dt = new DataTable(); dt.Load(dr); dataGridView1.DataSource = dt; dataGridView1.Refresh(); } } }