TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Display min, max and average records in textbox in c#
Satyapriya Nayak
Aug 30, 2011
8.4
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
Here I will show you how to Display min, max and average records in textbox in c#.
Here I will show you how to Display min, max and average records in textbox in c#.
Program
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
System.Data.OleDb;
namespace
Display_min_max_avg_records_in_textbox
{
public
partial
class
Form1
:
Form
{
string
ConnectionString = System.Configuration.
ConfigurationSettings
.AppSettings[
"dsn"
];
OleDbCommand
com;
OleDbDataAdapter
oledbda;
DataSet
ds =
new
DataSet
();
string
str;
public
Form1()
{
InitializeComponent();
}
private
void
Form1_Load(
object
sender,
EventArgs
e)
{
OleDbConnection
con =
new
OleDbConnection
(ConnectionString);
con.Open();
str =
"select * from student"
;
com =
new
OleDbCommand
(str, con);
oledbda =
new
OleDbDataAdapter
(com);
ds =
new
DataSet
();
oledbda.Fill(ds,
"student"
);
dataGridView1.DataSource = ds;
dataGridView1.DataMember =
"student"
;
con.Close();
}
private
void
button1_Click(
object
sender,
EventArgs
e)
{
OleDbConnection
con =
new
OleDbConnection
(ConnectionString);
con.Open();
str =
"select max(smarks)from student"
;
com =
new
OleDbCommand
(str, con);
textBox1.Text = com.ExecuteScalar().ToString();
con.Close();
}
private
void
button2_Click(
object
sender,
EventArgs
e)
{
OleDbConnection
con =
new
OleDbConnection
(ConnectionString);
con.Open();
str =
"select min(smarks)from student"
;
com =
new
OleDbCommand
(str, con);
textBox2.Text = com.ExecuteScalar().ToString();
con.Close();
}
private
void
button3_Click(
object
sender,
EventArgs
e)
{
OleDbConnection
con =
new
OleDbConnection
(ConnectionString);
con.Open();
str =
"select avg(smarks)from student"
;
com =
new
OleDbCommand
(str, con);
textBox3.Text = com.ExecuteScalar().ToString();
con.Close();
}
}
}
Output
Thanks
Display min
Next Recommended Reading
Add And Multiply Two Textbox Values And Automatically Display The Result In Third Textbox In C#