Disable Pen Drives Using C# .NET
//change password form source //pass.cs
Friday, February 03, 2012 | Labels: Disable and Enable Pen Drives, File Reading and Writing, Window Utility | 0 Comments
ADODB CONNECTION and RECORDSET IN C#.NET
Introduction This article talks you through the usage of ADODB connection in .NET application using C# language through SQLEXPRESS. The example details the data access using ADODB, fetching recordset, insert record into database
To download the Source Code Click Here
Step 1: add Reference for ADODB
Step 2 USE ADODB IN PROGRAM
*
* THISH IS DEMO OF ADODB CONNECTION IN C#.NET USING SQLEXPRESS
* AND SQL SERVER
* IN THIS PROGRAM SHOW HOW TO RETRIEVE RECORD USING ADODB RECORDSET
* AND EXECUTE QUERY
* AUTHER : SATYAVEER SINGH
* EMAIL: satya.parmar@gmail.com
* INDIA
*
*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using ADODB; // ADODB
namespace ADODBCONNECTION
{
public partial class Form1 : Form
{
ADODB.Connection conn; // ADODB CONNECTION
bool flag;
string sql;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// string str = "Provider=SQLOLEDB.1;uid=sa;password=1;database=Student;DataSource={local}";
string str="Provider=SQLOLEDB;Data Source=.\\SQLEXPRESS;Integrated Security=SSPI;Initial Catalog=Student;Initial File Name=E:\\DotNetWebSite\\ADODBCONNECTION\\ADODBCONNECTION\\Student.mdf";
conn = new ADODB.Connection();
conn.Open(str, "", "", -1); // connection Open
CmdAdd.Enabled = true; // Enable and Desable the buttons
cmdDel.Enabled = true;
cmdmodify.Enabled = true;
cmdCan.Enabled = false;
cmdCan.Enabled = false;
cmdSave.Enabled = false;
groupBox1.Enabled = false;
fillrecord();
}
private void CmdAdd_Click(object sender, EventArgs e)
{
sql = "select max(rollno) as rn from detail";
int num;
string str;
ADODB.Recordset rs = new ADODB.Recordset();
groupBox1.Enabled = true;
groupBox3.Enabled = false;
CmdAdd.Enabled = false;
cmdDel.Enabled = false;
cmdmodify.Enabled = false;
cmdCan.Enabled = true;
cmdCan.Enabled = true;
cmdSave.Enabled = true;
txtage.Text = "";
txtclass.Text = "";
txtname.Text="";
flag = false;
rs.Open(sql, conn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockBatchOptimistic, 0);
if (rs.Fields[0].Value == null)
{
num = 1;
}
else
{
num = int.Parse(rs.Fields["rn"].Value.ToString()) + 1;
}
if(num>=0 && num<10)
{
str = "00" + num.ToString();
}
else if (num >= 10 && num < 100)
{
str = "0" + num.ToString();
}
else
{
str = num.ToString();
}
txtroll.Text = str;
}
private void cmdCan_Click(object sender, EventArgs e)
{
CmdAdd.Enabled = true;
cmdDel.Enabled = true;
cmdmodify.Enabled = true;
cmdCan.Enabled = false;
cmdCan.Enabled = false;
cmdSave.Enabled = false;
if (flag == false)
{
txtage.Text = "";
txtclass.Text = "";
txtname.Text = "";
txtroll.Text = "";
}
groupBox1.Enabled = false;
groupBox3.Enabled = true;
flag = false;
}
private void cmdmodify_Click(object sender, EventArgs e)
{
flag = true;
groupBox3.Enabled = false;
groupBox1.Enabled = true;
CmdAdd.Enabled = false;
cmdDel.Enabled = false;
cmdmodify.Enabled = false;
cmdCan.Enabled = true;
cmdCan.Enabled = true;
cmdSave.Enabled = true;
}
private void cmdSave_Click(object sender, EventArgs e)
{
string sql;
object ret;
if (flag == false)
{// Sql query for insert data
sql = "insert into detail values('" + txtroll.Text + "','" + txtname.Text + "','"+ txtclass.Text + "'," + txtage.Text + ")";
}
else
{// Sql query for ipdate data
sql = "update detail set name='" + txtname.Text + "',class='" + txtclass.Text + "',age=" + txtage.Text + " where rollno='" + txtroll.Text + "'";
}
conn.Execute(sql,out ret,0); // Execute the query through ADODB CONNECTION
CmdAdd.Enabled = true;
cmdDel.Enabled = true;
cmdmodify.Enabled = true;
cmdCan.Enabled = false;
cmdCan.Enabled = false;
cmdSave.Enabled = false;
groupBox1.Enabled = false;
groupBox3.Enabled = true;
flag = false;
fillrecord();
}
private void cmdDel_Click(object sender, EventArgs e){
object ret;
if (txtroll.Text == "")
{
MessageBox.Show("there is no record to delete plz select record", "Alert");
}
else
{// Query To delete Record
sql = "delete from detail where rollno='" + txtroll.Text + "'";
conn.Execute(sql, out ret, 0);
txtage.Text = "";
txtclass.Text = "";
txtname.Text = "";
txtroll.Text = "";
fillrecord();
}
}
private void fillrecord() // Show tha all Record
{
ADODB.Recordset rs = new ADODB.Recordset(); // ADODB RECORDSET
sql = "select rollno,name from detail";
// RECORDSET OPEN
rs.Open(sql,conn,ADODB.CursorTypeEnum.adOpenStatic,ADODB.LockTypeEnum.adLockBatchOptimistic,0);
listBox1.Items.Clear();
while (rs.EOF == false)
{
listBox1.Items.Add(rs.Fields[0].Value.ToString() + " || " + rs.Fields[1].Value.ToString());
rs.MoveNext();
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string rollno;
rollno = listBox1.SelectedItem.ToString().Substring(0,3);
ADODB.Recordset rs = new ADODB.Recordset();
sql = "select * from detail where rollno='" + rollno + "'";
rs.Open(sql, conn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockBatchOptimistic, 0);
txtroll.Text = rollno;
txtname.Text = rs.Fields[1].Value.ToString();
txtclass.Text = rs.Fields[2].Value.ToString();
txtage.Text = rs.Fields[3].Value.ToString();
}
}
}
/////////
MAIN WINDOW
To download the Source Code Click Here
Monday, January 30, 2012 | Labels: ADO, ADODB Connection, ADODB Recordset, Sql Express | 0 Comments
Love of nature...
Rain is not only drops of water.
It is the LOVE of sky 4 earth.
They never meet each other but send LOVE this way.
Enjoy the LOVE of nature... :)
Monday, July 25, 2011 | | 2 Comments
Defination of love
What is LOVE ?
Love is when my mom comes to me at night & say
"Beta,
I love you"
Love is when I come back from Collage & papa says
"Beta,
late hone wala tha to call kar deta?"
Love is when my
sister says,
"Bhai,meri shadi ke baad mujse jhagda kaun karega?"
Love
is when I'm moodless & my brother says,
"Chal kahi ghumne jate
hai"
Love is when my best friends call me & say,
"Ooe !
tere bina dil nahi lagta"
That's love...
DONT MISS IT IN LIFE
LovE
iS NoT onLY Having GF or BF..
dis love is betteR ThaN HAviNg GF or BF..
Wednesday, June 09, 2010 | | 1 Comments
Welcome Note
You are most Welcome on my blog. this is my first post for my blog
Sunday, June 06, 2010 | | 0 Comments