0% found this document useful (0 votes)
10 views3 pages

Lab 12 Solved

The document describes a C# application for connecting a database with Visual Studio using OleDb. It includes methods for inserting, updating, and retrieving student data from a database named 'bseStudent.accdb'. The application provides user feedback through message boxes for successful operations or errors encountered during database interactions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Lab 12 Solved

The document describes a C# application for connecting a database with Visual Studio using OleDb. It includes methods for inserting, updating, and retrieving student data from a database named 'bseStudent.accdb'. The application provides user feedback through message boxes for successful operations or errors encountered during database interactions.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

 Name : Syeda Farwa Batool

 Roll no : 2022-BSE-071
 Course : Database Systems
 Lab : 12

Connection of Database with Visual Studio


System;
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
using [Link];
namespace Sadaf_Lab11
{
public partial class Form1 : Form
{
private OleDbConnection connection=new OleDbConnection();
string result;
bool temp = false;
public Form1()
{
InitializeComponent();
try
{
[Link] = @"Provider=[Link].12.0;Data Source=E:\BSE-
IV\BSE-IV\VP Lab\Sadaf_Lab11\[Link];Persist Security Info=False;";
[Link]("Connection Succeeded");
}
catch (Exception ex0)
{
[Link]("Error="+ex0);
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
[Link]();
OleDbCommand command = new OleDbCommand();
[Link] = connection;
[Link] = "insert into BSE5A (Reg_no, FName, LName, DOB, email, NIC_no,
GPA, CGPA) values ('" + [Link] + "','" + [Link] + "','" + [Link] + "','" +
[Link] + "','" + [Link] + "','" + [Link] + "'," + [Link] + "," + [Link]
+ ")";
int s=[Link]();
if(s!=0)
[Link]("Data Added Successfully");
[Link]();
}
catch (Exception ex1)
{
[Link]("ERROR =" + ex1);
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
[Link]();
OleDbCommand command=new OleDbCommand();
[Link]=connection;
[Link] = "update BSE5A set GPA="+[Link]+",
CGPA="+[Link]+" where Reg_no='"+[Link]+"'";
[Link]();
[Link]("Data Updated Successfully");
[Link]();
}
catch (Exception ex3)
{
[Link]("ERROR =" + ex3);
}
}
private void button3_Click(object sender, EventArgs e)
{
try
{
[Link]();
OleDbCommand command = new OleDbCommand();
[Link] = connection;
[Link] = "select * from BSE5A where FName='"+[Link]+"'";
OleDbDataReader rdr = [Link]();
if([Link]())
{
result = rdr["Reg_no"].ToString() + "\n" + rdr["FName"].ToString() + "\n" +
rdr["LName"].ToString() + "\n" + rdr["DOB"].ToString() + "\n" + rdr["email"].ToString() + "\n" +
rdr["NIC_no"].ToString() + "\n" + rdr["GPA"].ToString() + "\n" + rdr["CGPA"].ToString();
[Link](result);
}
else
[Link]("not found");
[Link]();
}
catch (Exception ex4)
{
[Link]("ERROR =" + ex4);
}
}
}
}
Database:
Output:

You might also like