SQLServer
刷新缓存,代码提示
级联在外键后面添加
on
delete
cascade
vs快捷键
- 恢复默认设置 工具 - 导入和导出设置 - 重置所有设置
- ctrl+j == alt+/
- 打try-catch tab tab 两次
必备头文件:
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
FormMain.cs
控件: MenuStrip
属性:IsMdiContainer : True
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;
namespace
my2017
{
public
partial
class
FormMain
:
Form
{
public
FormMain()
{
InitializeComponent();
}
private
void
信息查询ToolStripMenuItem_Click(
object
sender,
EventArgs
e)
{
FormSearch
fs =
new
FormSearch
();
fs.MdiParent =
this
;
fs.Show();
}
private
void
信息统计ToolStripMenuItem_Click(
object
sender,
EventArgs
e)
{
FormStatistics
fss =
new
FormStatistics
();
fss.MdiParent =
this
;
fss.Show();
}
private
void
病人信息表维护ToolStripMenuItem_Click(
object
sender,
EventArgs
e)
{
FormPatient
fp =
new
FormPatient
();
fp.MdiParent =
this
;
fp.Show();
}
private
void
小科室表维护ToolStripMenuItem_Click(
object
sender,
EventArgs
e)
{
FormGroup
fg =
new
FormGroup
();
fg.MdiParent =
this
;
fg.Show();
}
private
void
退出程序ToolStripMenuItem_Click(
object
sender,
EventArgs
e)
{
Application
.Exit();
}
}
}
DBHelperSQL.cs
@"server = admin-THINK; database = my2017; Trusted_Connection = SSPI;"
;
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Data;
using
System.Data.SqlClient;
using
System.Windows.Forms;
namespace
my2017
{
class
DBHelperSQL
{
///
<summary>
///
连接字符串
///
</summary>
public
static
string
connStr =
@"server = admin-THINK; database = my2017; integrated security = true;"
;
///
<summary>
///
连接实例初始值为空
///
</summary>
public
static
SqlConnection
conn =
null
;
///
<summary>
///
查询
///
</summary>
///
<param name="sql"></param>
///
<param name="para"></param>
///
<returns></returns>
public
static
DataTable
tableSelect(
string
sql,
SqlParameter
[] para =
null
)
{
try
{
SqlCommand
cmd =
new
SqlCommand
(sql, conn);
if
(para !=
null
)
cmd.Parameters.AddRange(para);
DataTable
dt =
new
DataTable
();
SqlDataAdapter
da =
new
SqlDataAdapter
(cmd);
da.Fill(dt);
return
dt;
}
catch
(
Exception
ex)
{
MessageBox
.Show(ex.Message);
return
null
;
}
}
///
<summary>
///
增删改
///
</summary>
///
<param name="sql"></param>
///
<param name="para"></param>
public
static
void
tableChange(
string
sql,
SqlParameter
[] para =
null
)
{
try
{
SqlCommand
cmd =
new
SqlCommand
(sql, conn);
if
(para !=
null
)
cmd.Parameters.AddRange(para);
if
(cmd.ExecuteNonQuery() > 0)
{
MessageBox
.Show(
"操作成功!"
);
}
else
{
MessageBox
.Show(
"操作失败! \n请检查数据库是否存在此数据!"
);
}
}
catch
(
Exception
ex)
{
MessageBox
.Show(ex.Message);
}
}
}
}
Program.cs
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Windows.Forms;
using
System.Data;
using
System.Data.SqlClient;
namespace
my2017
{
static
class
Program
{
///
<summary>
///
应用程序的主入口点。
///
</summary>
[
STAThread
]
static
void
Main()
{
Application
.EnableVisualStyles();
Application
.SetCompatibleTextRenderingDefault(
false
);
try
{
DBHelperSQL
.conn =
new
SqlConnection
(
DBHelperSQL
.connStr);
DBHelperSQL
.conn.Open();
}
catch
(
Exception
ex)
{
MessageBox
.Show(ex.Message);
}
Application
.Run(
new
FormMain
());
DBHelperSQL
.conn.Close();
}
}
}
FormPatient.cs
控件: DataGridView
属性:AutoSizeColumnsMode : Fill
using
System;
using
System.Collections.Generic;
using
System.ComponentModel
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Data;
using
System.Data.SqlClient;
using
System.Windows.Forms;
namespace
my2017
{
public
partial
class
FormPatient
:
Form
{
public
FormPatient()
{
InitializeComponent();
}
private
void
btnAdd_Click(
object
sender,
EventArgs
e)
{
string
sql =
@"INSERT INTO [my2017].[dbo].[Patient]
([PID]
,[PName]
,[Date]
,[GroupNo])
VALUES(@PID,@PName,@Date,@GroupNo)"
;
SqlParameter
[] para = {
new
SqlParameter
(
"@PID"
, txtPID.Text),
new
SqlParameter
(
"@PName"
, txtPName.Text),
new
SqlParameter
(
"@Date"
, txtDate.Text),
new
SqlParameter
(
"@GroupNo"
, cboGroupNo.SelectedValue.ToString())};
DBHelperSQL
.tableChange(sql, para);
myShow();
}
private
void
btnDel_Click(
object
sender,
EventArgs
e)
{
string
sql =
@"DELETE FROM [my2017].[dbo].[Patient]
WHERE [PID] = @PID"
;
SqlParameter
[] para = {
new
SqlParameter
(
"@PID"
, txtPID.Text) };
DBHelperSQL
.tableChange(sql, para);
myShow();
}
private
void
btnAlt_Click(
object
sender,
EventArgs
e)
{
string
sql =
@"UPDATE [my2017].[dbo].[Patient]
SET [PName] = @PName
,[Date] = @Date
,[GroupNo] = @GroupNo
WHERE [PID] = @PID"
;
SqlParameter
[] para = {
new
SqlParameter
(
"@PID"
, txtPID.Text),
new
SqlParameter
(
"@PName"
, txtPName.Text),
new
SqlParameter
(
"@Date"
, txtDate.Text),
new
SqlParameter
(
"@GroupNo"
, cboGroupNo.SelectedValue.ToString())};
DBHelperSQL
.tableChange(sql, para);
myShow();
}
private
void
btnSelect_Click(
object
sender,
EventArgs
e)
{
myShow();
}
private
void
myShow()
{
string
sql =
@"SELECT [PID]
,[PName]
,[Date]
,[GroupNo]
FROM [my2017].[dbo].[Patient]"
;
dv.DataSource =
DBHelperSQL
.tableSelect(sql);
}
private
void
FormPatient_Load(
object
sender,
EventArgs
e)
{
string
sqlG =
@"SELECT [GroupNo]
,[GroupName]
,[DeptNo]
,[Month]
,[Number]
FROM [my2017].[dbo].[Group]"
;
DataTable
dtG =
DBHelperSQL
.tableSelect(sqlG);
cboGroupNo.DataSource = dtG;
cboGroupNo.DisplayMember = dtG.Columns[
"GroupNo"
].ToString();
cboGroupNo.ValueMember = dtG.Columns[
"GroupNo"
].ToString();
cboGroupNo.SelectedIndex = 0;
}
}
}
FormSearch.cs
控件: DataGridView
属性:AutoSizeColumnsMode : Fill
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;
namespace
my2017
{
public
partial
class
FormSearch
:
Form
{
public
FormSearch()
{
InitializeComponent();
}
private
void
FormSearch_Load(
object
sender,
EventArgs
e)
{
string
sqlD =
@"SELECT [DeptNo]
,[DeptName]
FROM [my2017].[dbo].[Department]"
;
DataTable
dtD =
DBHelperSQL
.tableSelect(sqlD);
cboDeptName.DataSource = dtD;
cboDeptName.DisplayMember = dtD.Columns[
"DeptName"
].ToString();
cboDeptName.ValueMember = dtD.Columns[
"DeptName"
].ToString();
cboDeptName.SelectedIndex = 0;
string
sqlG =
@"SELECT [GroupNo]
,[GroupName]
,[DeptNo]
,[Month]
,[Number]
FROM [my2017].[dbo].[Group]"
;
DataTable
dtG =
DBHelperSQL
.tableSelect(sqlG);
cboGroupName.DataSource = dtG;
cboGroupName.DisplayMember = dtG.Columns[
"GroupName"
].ToString();
cboGroupName.ValueMember = dtG.Columns[
"GroupName"
].ToString();
cboGroupName.SelectedIndex = 0;
}
private
void
btnSelect_Click(
object
sender,
EventArgs
e)
{
string
sql =
@"select d.DeptName, g.GroupName, p.PName
from Patient p, [Group] g, Department d
where p.GroupNo = g.GroupNo and g.DeptNo = d.DeptNo "
;
if
(chbDeptName.CheckState ==
CheckState
.Checked)
{
sql +=
string
.Format(
@"and d.DeptName = '{0}'"
, cboDeptName.SelectedValue.ToString());
}
if
(chbGroupName.CheckState ==
CheckState
.Checked)
{
sql +=
string
.Format(
@"and g.GroupName = '{0}'"
, cboGroupName.SelectedValue.ToString());
}
if
(chbPName.CheckState ==
CheckState
.Checked)
{
sql +=
string
.Format(
@"and p.PName like '%{0}%'"
, txtPName.Text);
}
sql +=
@" order by d.DeptNo desc, g.GroupNo, p.PID desc"
;
dv.DataSource =
DBHelperSQL
.tableSelect(sql);
}
}
}
FormStatistics.cs
控件: DataGridView
属性:AutoSizeColumnsMode : Fill
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;
namespace
my2017
{
public
partial
class
FormStatistics
:
Form
{
public
FormStatistics()
{
InitializeComponent();
}
private
void
btn1_Click(
object
sender,
EventArgs
e)
{
string
sql =
@"select g.DeptNo 大科室编号, d.DeptName 大科室名, SUM(g.Number) 病人总数
from [Group] g join Department d on g.DeptNo = d.DeptNo
group by g.DeptNo, d.DeptName"
;
dv.DataSource =
DBHelperSQL
.tableSelect(sql);
}
private
void
btn2_Click(
object
sender,
EventArgs
e)
{
string
sql =
@"select g.[Month] 月份, SUM(Number) 病人总数
from [Group] g
group by g.[Month]"
;
dv.DataSource =
DBHelperSQL
.tableSelect(sql);
}
}
}
使用Text显示 返回一行数据:
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;
using
System.Data.SqlClient;
namespace
my2017
{
public
partial
class
FormMaxMin
:
Form
{
public
FormMaxMin()
{
InitializeComponent();
}
private
void
FormMaxMin_Load(
object
sender,
EventArgs
e)
{
string
sqlMax =
@"select GroupNo, GroupName, Number
from [Group]
where Number in (select Max(Number) from [Group])"
;
string
sqlMin=
@"select GroupNo, GroupName, Number
from [Group]
where Number in (select Min(Number) from [Group])"
;
try
{
//最??大???值??
SqlCommand
cmd =
new
SqlCommand
(sqlMax,
DBHelperSQL
.conn);
txtMaxMin.AppendText(
"最大值:\n"
);
SqlDataReader
rdr = cmd.ExecuteReader();
while
(rdr.Read())
{
txtMaxMin.AppendText(
"GroupNo: "
+ rdr.GetValue(0) +
" "
+
"GroupName: "
+ rdr.GetValue(1) +
" "
+
"Number: "
+ rdr.GetValue(2) +
"\n"
);
}
rdr.Close();
//最??小?值??
cmd.CommandText = sqlMin;
txtMaxMin.AppendText(
"最小值:\n"
);
rdr = cmd.ExecuteReader();
while
(rdr.Read())
{
txtMaxMin.AppendText(
"GroupNo: "
+ rdr.GetValue(0) +
" "
+
"GroupName: "
+ rdr.GetValue(1) +
" "
+
"Number: "
+ rdr.GetValue(2) +
"\n"
);
}
rdr.Close();
}
catch
(
Exception
ex)
{
MessageBox
.Show(ex.Message);
}
}
}
}
SQLServer
刷新缓存,代码提示
级联在外键后面添加
on
delete
cascade
vs快捷键
- 恢复默认设置 工具 - 导入和导出设置 - 重置所有设置
- ctrl+j == alt+/
- 打try-catch tab tab 两次
必备头文件:
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
FormMain.cs
控件: MenuStrip
属性:IsMdiContainer : True
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;
namespace
my2017
{
public
partial
class
FormMain
:
Form
{
public
FormMain()
{
InitializeComponent();
}
private
void
信息查询ToolStripMenuItem_Click(
object
sender,
EventArgs
e)
{
FormSearch
fs =
new
FormSearch
();
fs.MdiParent =
this
;
fs.Show();
}
private
void
信息统计ToolStripMenuItem_Click(
object
sender,
EventArgs
e)
{
FormStatistics
fss =
new
FormStatistics
();
fss.MdiParent =
this
;
fss.Show();
}
private
void
病人信息表维护ToolStripMenuItem_Click(
object
sender,
EventArgs
e)
{
FormPatient
fp =
new
FormPatient
();
fp.MdiParent =
this
;
fp.Show();
}
private
void
小科室表维护ToolStripMenuItem_Click(
object
sender,
EventArgs
e)
{
FormGroup
fg =
new
FormGroup
();
fg.MdiParent =
this
;
fg.Show();
}
private
void
退出程序ToolStripMenuItem_Click(
object
sender,
EventArgs
e)
{
Application
.Exit();
}
}
}
DBHelperSQL.cs
@"server = admin-THINK; database = my2017; Trusted_Connection = SSPI;"
;
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Data;
using
System.Data.SqlClient;
using
System.Windows.Forms;
namespace
my2017
{
class
DBHelperSQL
{
///
<summary>
///
连接字符串
///
</summary>
public
static
string
connStr =
@"server = admin-THINK; database = my2017; integrated security = true;"
;
///
<summary>
///
连接实例初始值为空
///
</summary>
public
static
SqlConnection
conn =
null
;
///
<summary>
///
查询
///
</summary>
///
<param name="sql"></param>
///
<param name="para"></param>
///
<returns></returns>
public
static
DataTable
tableSelect(
string
sql,
SqlParameter
[] para =
null
)
{
try
{
SqlCommand
cmd =
new
SqlCommand
(sql, conn);
if
(para !=
null
)
cmd.Parameters.AddRange(para);
DataTable
dt =
new
DataTable
();
SqlDataAdapter
da =
new
SqlDataAdapter
(cmd);
da.Fill(dt);
return
dt;
}
catch
(
Exception
ex)
{
MessageBox
.Show(ex.Message);
return
null
;
}
}
///
<summary>
///
增删改
///
</summary>
///
<param name="sql"></param>
///
<param name="para"></param>
public
static
void
tableChange(
string
sql,
SqlParameter
[] para =
null
)
{
try
{
SqlCommand
cmd =
new
SqlCommand
(sql, conn);
if
(para !=
null
)
cmd.Parameters.AddRange(para);
if
(cmd.ExecuteNonQuery() > 0)
{
MessageBox
.Show(
"操作成功!"
);
}
else
{
MessageBox
.Show(
"操作失败! \n请检查数据库是否存在此数据!"
);
}
}
catch
(
Exception
ex)
{
MessageBox
.Show(ex.Message);
}
}
}
}
Program.cs
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Windows.Forms;
using
System.Data;
using
System.Data.SqlClient;
namespace
my2017
{
static
class
Program
{
///
<summary>
///
应用程序的主入口点。
///
</summary>
[
STAThread
]
static
void
Main()
{
Application
.EnableVisualStyles();
Application
.SetCompatibleTextRenderingDefault(
false
);
try
{
DBHelperSQL
.conn =
new
SqlConnection
(
DBHelperSQL
.connStr);
DBHelperSQL
.conn.Open();
}
catch
(
Exception
ex)
{
MessageBox
.Show(ex.Message);
}
Application
.Run(
new
FormMain
());
DBHelperSQL
.conn.Close();
}
}
}
FormPatient.cs
控件: DataGridView
属性:AutoSizeColumnsMode : Fill
using
System;
using
System.Collections.Generic;
using
System.ComponentModel
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Data;
using
System.Data.SqlClient;
using
System.Windows.Forms;
namespace
my2017
{
public
partial
class
FormPatient
:
Form
{
public
FormPatient()
{
InitializeComponent();
}
private
void
btnAdd_Click(
object
sender,
EventArgs
e)
{
string
sql =
@"INSERT INTO [my2017].[dbo].[Patient]
([PID]
,[PName]
,[Date]
,[GroupNo])
VALUES(@PID,@PName,@Date,@GroupNo)"
;
SqlParameter
[] para = {
new
SqlParameter
(
"@PID"
, txtPID.Text),
new
SqlParameter
(
"@PName"
, txtPName.Text),
new
SqlParameter
(
"@Date"
, txtDate.Text),
new
SqlParameter
(
"@GroupNo"
, cboGroupNo.SelectedValue.ToString())};
DBHelperSQL
.tableChange(sql, para);
myShow();
}
private
void
btnDel_Click(
object
sender,
EventArgs
e)
{
string
sql =
@"DELETE FROM [my2017].[dbo].[Patient]
WHERE [PID] = @PID"
;
SqlParameter
[] para = {
new
SqlParameter
(
"@PID"
, txtPID.Text) };
DBHelperSQL
.tableChange(sql, para);
myShow();
}
private
void
btnAlt_Click(
object
sender,
EventArgs
e)
{
string
sql =
@"UPDATE [my2017].[dbo].[Patient]
SET [PName] = @PName
,[Date] = @Date
,[GroupNo] = @GroupNo
WHERE [PID] = @PID"
;
SqlParameter
[] para = {
new
SqlParameter
(
"@PID"
, txtPID.Text),
new
SqlParameter
(
"@PName"
, txtPName.Text),
new
SqlParameter
(
"@Date"
, txtDate.Text),
new
SqlParameter
(
"@GroupNo"
, cboGroupNo.SelectedValue.ToString())};
DBHelperSQL
.tableChange(sql, para);
myShow();
}
private
void
btnSelect_Click(
object
sender,
EventArgs
e)
{
myShow();
}
private
void
myShow()
{
string
sql =
@"SELECT [PID]
,[PName]
,[Date]
,[GroupNo]
FROM [my2017].[dbo].[Patient]"
;
dv.DataSource =
DBHelperSQL
.tableSelect(sql);
}
private
void
FormPatient_Load(
object
sender,
EventArgs
e)
{
string
sqlG =
@"SELECT [GroupNo]
,[GroupName]
,[DeptNo]
,[Month]
,[Number]
FROM [my2017].[dbo].[Group]"
;
DataTable
dtG =
DBHelperSQL
.tableSelect(sqlG);
cboGroupNo.DataSource = dtG;
cboGroupNo.DisplayMember = dtG.Columns[
"GroupNo"
].ToString();
cboGroupNo.ValueMember = dtG.Columns[
"GroupNo"
].ToString();
cboGroupNo.SelectedIndex = 0;
}
}
}
FormSearch.cs
控件: DataGridView
属性:AutoSizeColumnsMode : Fill
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;
namespace
my2017
{
public
partial
class
FormSearch
:
Form
{
public
FormSearch()
{
InitializeComponent();
}
private
void
FormSearch_Load(
object
sender,
EventArgs
e)
{
string
sqlD =
@"SELECT [DeptNo]
,[DeptName]
FROM [my2017].[dbo].[Department]"
;
DataTable
dtD =
DBHelperSQL
.tableSelect(sqlD);
cboDeptName.DataSource = dtD;
cboDeptName.DisplayMember = dtD.Columns[
"DeptName"
].ToString();
cboDeptName.ValueMember = dtD.Columns[
"DeptName"
].ToString();
cboDeptName.SelectedIndex = 0;
string
sqlG =
@"SELECT [GroupNo]
,[GroupName]
,[DeptNo]
,[Month]
,[Number]
FROM [my2017].[dbo].[Group]"
;
DataTable
dtG =
DBHelperSQL
.tableSelect(sqlG);
cboGroupName.DataSource = dtG;
cboGroupName.DisplayMember = dtG.Columns[
"GroupName"
].ToString();
cboGroupName.ValueMember = dtG.Columns[
"GroupName"
].ToString();
cboGroupName.SelectedIndex = 0;
}
private
void
btnSelect_Click(
object
sender,
EventArgs
e)
{
string
sql =
@"select d.DeptName, g.GroupName, p.PName
from Patient p, [Group] g, Department d
where p.GroupNo = g.GroupNo and g.DeptNo = d.DeptNo "
;
if
(chbDeptName.CheckState ==
CheckState
.Checked)
{
sql +=
string
.Format(
@"and d.DeptName = '{0}'"
, cboDeptName.SelectedValue.ToString());
}
if
(chbGroupName.CheckState ==
CheckState
.Checked)
{
sql +=
string
.Format(
@"and g.GroupName = '{0}'"
, cboGroupName.SelectedValue.ToString());
}
if
(chbPName.CheckState ==
CheckState
.Checked)
{
sql +=
string
.Format(
@"and p.PName like '%{0}%'"
, txtPName.Text);
}
sql +=
@" order by d.DeptNo desc, g.GroupNo, p.PID desc"
;
dv.DataSource =
DBHelperSQL
.tableSelect(sql);
}
}
}
FormStatistics.cs
控件: DataGridView
属性:AutoSizeColumnsMode : Fill
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;
namespace
my2017
{
public
partial
class
FormStatistics
:
Form
{
public
FormStatistics()
{
InitializeComponent();
}
private
void
btn1_Click(
object
sender,
EventArgs
e)
{
string
sql =
@"select g.DeptNo 大科室编号, d.DeptName 大科室名, SUM(g.Number) 病人总数
from [Group] g join Department d on g.DeptNo = d.DeptNo
group by g.DeptNo, d.DeptName"
;
dv.DataSource =
DBHelperSQL
.tableSelect(sql);
}
private
void
btn2_Click(
object
sender,
EventArgs
e)
{
string
sql =
@"select g.[Month] 月份, SUM(Number) 病人总数
from [Group] g
group by g.[Month]"
;
dv.DataSource =
DBHelperSQL
.tableSelect(sql);
}
}
}
使用Text显示 返回一行数据:
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;
using
System.Data.SqlClient;
namespace
my2017
{
public
partial
class
FormMaxMin
:
Form
{
public
FormMaxMin()
{
InitializeComponent();
}
private
void
FormMaxMin_Load(
object
sender,
EventArgs
e)
{
string
sqlMax =
@"select GroupNo, GroupName, Number
from [Group]
where Number in (select Max(Number) from [Group])"
;
string
sqlMin=
@"select GroupNo, GroupName, Number
from [Group]
where Number in (select Min(Number) from [Group])"
;
try
{
//最??大???值??
SqlCommand
cmd =
new
SqlCommand
(sqlMax,
DBHelperSQL
.conn);
txtMaxMin.AppendText(
"最大值:\n"
);
SqlDataReader
rdr = cmd.ExecuteReader();
while
(rdr.Read())
{
txtMaxMin.AppendText(
"GroupNo: "
+ rdr.GetValue(0) +
" "
+
"GroupName: "
+ rdr.GetValue(1) +
" "
+
"Number: "
+ rdr.GetValue(2) +
"\n"
);
}
rdr.Close();
//最??小?值??
cmd.CommandText = sqlMin;
txtMaxMin.AppendText(
"最小值:\n"
);
rdr = cmd.ExecuteReader();
while
(rdr.Read())
{
txtMaxMin.AppendText(
"GroupNo: "
+ rdr.GetValue(0) +
" "
+
"GroupName: "
+ rdr.GetValue(1) +
" "
+
"Number: "
+ rdr.GetValue(2) +
"\n"
);
}
rdr.Close();
}
catch
(
Exception
ex)
{
MessageBox
.Show(ex.Message);
}
}
}
}