0% found this document useful (0 votes)
9 views9 pages

Database in Winform

database questions

Uploaded by

jadhavsai4321
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)
9 views9 pages

Database in Winform

database questions

Uploaded by

jadhavsai4321
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
You are on page 1/ 9

1.

DB related for ins, del, update and select :( table course, student, studentfees ), Without procedure
means writing full code for each query.

OleDb (Object Linking and Embedding, Database):

• OleDb is a data access technology used to connect and interact with databases from
Windows applications. It provides a generic interface for accessing various database
systems, including Microsoft Access, Excel, SQL Server, Oracle, and others.
• Components:
o OleDbConnection: Establishes a connection to the database.
o OleDbCommand: Executes SQL queries and commands against the database.
o OleDbDataReader: Retrieves and iterates through data returned by SELECT
queries.
o OleDbDataAdapter: Facilitates data retrieval and manipulation with datasets,
enabling data binding to WinForms controls.
o BindingSource: Acts as a mediator between data sources and data-bound
controls, facilitating data binding in WinForms applications. Used mainly for
navigations.
o Dataset: a Dataset acts as a local storage for data retrieved from a database. It
allows your application to work with data even when offline, enabling
manipulation and updates before reconnecting to the database

0. Global Declaration:
OleDbConnection cn;
OleDbCommand co;
OleDbDataAdapter da;
BindingSource bs;
DataSet ds;
1. Data connection:
cn= new OleDbConnection("Connection string ");
cn.Open();

2. OperationS:
a. Retrieve/select:
Displays Records from dataset using binding sources:
B. Insert

C. UPDATE:
D. Delete:

E. Navigating using Binding source:


It has inbuilt necessary code for navigation so no need to write it

On Next Button: bs.MoveFirst(); for navigating to next record

On last Button: bs.MoveLast(); for navigating to last record

On first Button: bs.MoveFirst(); for navigating to First record

On previous Button: bs.MoveFirst(); for navigating to previous record

3. Closing connection:
cn.Close();
Ensures the connection is properly closed after each operation.
Q. Write a query to calculate the remaining fees:

A.Code for search button


cn= new A : explanation
OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data this code demonstrate the
Source=C:\\Users\\pawar\\OneDrive\\Documents\\School.mdb"); searching of course based on Cno
cn.Open();
i.e. Course number
co=cn.CreateCommand();

co.CommandText = "SELECT St.S_Name, Co.cname, Co.fees,


REC.Rec_amt FROM Student St, Course Co, Recipt_details REC
WHERE St.cno=Co.cno AND REC.Roll_No=St.Roll_No AND
St.Roll_No=?";

co.Parameters.AddWithValue("Roll_No", textBox1.Text);
dr = co.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
textBox2.Text = dr[0].ToString();
textBox3.Text = dr[1].ToString();
textBox4.Text = dr[2].ToString();
textBox5.Text = dr[3].ToString();
}

else
{
MessageBox.Show("NAAAAA!");
}
dr.Close();

cn.Close();

B. Code for FEES TO BE PAID Button


B : explanation
this code demonstrate the
calculation of remaining fees
Q2. PROCEDURE
DB related for ins, del, update and select :( table course, student, studentfees ), With procedure means
writing full code for each query.

1. A stored procedure is a precompiled collection of SQL statements stored under a


name and processed as a unit. They encapsulate the logic required to interact with
the database and provide a layer of abstraction between the database and the
application.
2. Global declaration
SqlConnection cn;// Establishes a connection to a SQL Server database.
SqlCommand co;// Represents a SQL statement or stored procedure to execute against the
//database.
SqlDataReader dr;// Provides a way to read a forward-only stream of rows from a SQL Server
//database.

3. Establishing Connection
cn = new SqlConnection("Connection string");
cn.Open();
4. Operation:
1. Search:

WINFORM CODE
Procedure
2. Insert:

WINFORM CODE
Procedure

3. Delete
4.Update:

CLOSING CONNECTION:
CN.CLOSE
Q. Calculate the remaining using procedure:
1. Connect button
2.
Course fee button:
3.remainingfees
Here we have to input roll number

You might also like