Documente Academic
Documente Profesional
Documente Cultură
NET Examples
Connected Environment
Database Name : SP
Table Name : Emp
Emp_id int --
Emp_Name varchar 50
Salary int --
Data.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
namespace DataBase
{
class Data
{
SqlConnection con;
SqlCommand cmd;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DataBase
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
frm_Add.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DataBase
{
public partial class frm_Add : Form
{
public frm_Add()
{
InitializeComponent();
}
frm_Delete.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace DataBase
{
public partial class frm_Delete : Form
{
public frm_Delete()
{
InitializeComponent();
}
private void frm_Delete_Load(object sender, EventArgs e)
{
Data db = new Data();
db.Connect();
SqlDataReader dr = db.GetID();
while (dr.Read())
{
comboBox1.Items.Add(dr[0].ToString());
}
db.DisConnect();
}
frm_Modify.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace DataBase
{
public partial class frm_Modify : Form
{
public frm_Modify()
{
InitializeComponent();
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace DataBase
{
public partial class frm_Display : Form
{
static int id;
public frm_Display()
{
InitializeComponent();
}
Stored Procedures
if(@c=0)
select @eid=100
else
begin
select @c=max(emp_id) from emp
select @eid=@c+1
end
Database.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace database_conn
{
class Database
{
SqlConnection con;
SqlCommand cmd;
int
id=Convert.ToInt32(cmd.Parameters["@eid"].Value);
return id;
}
}
}
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DataBase
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}
frm_Add.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DataBase
{
public partial class frm_Add : Form
{
public frm_Add()
{
InitializeComponent();
}
frm_Delete.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace DataBase
{
public partial class frm_Delete : Form
{
public frm_Delete()
{
InitializeComponent();
}
frm_Modify.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace DataBase
{
public partial class frm_Modify : Form
{
public frm_Modify()
{
InitializeComponent();
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace DataBase
{
public partial class frm_Display : Form
{
static int id;
public frm_Display()
{
InitializeComponent();
}
DisConnected Environment
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace DisConnected
{
public partial class Form1 : Form
{
public static SqlConnection con;
public static SqlDataAdapter da;
public static DataSet ds;
public Form1()
{
InitializeComponent();
}
private void
displayRecordsToolStripMenuItem_Click(object sender,
EventArgs e)
{
frm_Display f = new frm_Display();
f.Show();
}
private void
deleteRecordToolStripMenuItem_Click(object sender, EventArgs
e)
{
frm_Delete f = new frm_Delete();
f.Show();
}
private void
modifyRecordToolStripMenuItem_Click(object sender, EventArgs
e)
{
frm_Modify_ f = new frm_Modify_();
f.Show();
}
private void
finalUpdationToolStripMenuItem_Click(object sender,
EventArgs e)
{
SqlCommandBuilder sb = new
SqlCommandBuilder(Form1.da);
Form1.da.Update(Form1.ds,"T1");
MessageBox.Show("Data Updated At Server Side");
}
}
}
frm_Add.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DisConnected
{
public partial class frm_Add : Form
{
public frm_Add()
{
InitializeComponent();
}
frm_Delete.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DisConnected
{
public partial class frm_Delete : Form
{
public frm_Delete()
{
InitializeComponent();
}
frm_Modify.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DisConnected
{
public partial class frm_Modify_ : Form
{
public frm_Modify_()
{
InitializeComponent();
}
frm_Display.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DisConnected
{
public partial class frm_Display : Form
{
public frm_Display()
{
InitializeComponent();
}
Database Name : SP
Table Name : Emp
Emp_id int --
Emp_Name varchar 50
Salary int --
Form1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
DataTable dt;
static int Emp_id;
public Form1()
{
InitializeComponent();
}
dt = new DataTable("Emp");
DataColumn dc1 = new DataColumn("eid", typeof(int));
DataColumn dc2 = new DataColumn("ename", typeof(string));
DataColumn dc3 = new DataColumn("salary", typeof(int));
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
dt.Columns.Add(dc3);
}
private void EnableControl()
{
button1.Enabled = false;
button2.Enabled = true;
button3.Enabled = false;
button4.Enabled = false;
button5.Enabled = false;
textBox1.Enabled = true;
textBox2.Enabled = true;
textBox3.Enabled = true;
textBox1.Focus();
}
}
namespace WindowsApplication2
{
public partial class Form1 : Form
{
DataSet ds;
static int pos = 0;
static int rowcount = 0;
public Form1()
{
InitializeComponent();
}
}
private void MakeReadOnly()
{
textBox1.ReadOnly = true;
textBox2.ReadOnly = true;
textBox3.ReadOnly = true;
}
private void ShowRecord()
{
textBox1.Text = ds.Tables[0].Rows[pos][0].ToString();
textBox2.Text = ds.Tables[0].Rows[pos][1].ToString();
textBox3.Text = ds.Tables[0].Rows[pos][2].ToString();
}
ShowRecord();
}
ShowRecord();
}
private void button5_Click(object sender, EventArgs e)
{
Application.Exit();
}
}
}