WinForm绑定DataGridView,日历datetimepicker,SplitContainer控件
使用SplitContainer控件将屏幕分成两部分。
方式一:
直接使用绑定数据源
就可以用EF的形式绑定数据源了。
可以添加列和编辑列
方式二:
采用手动连接MySQL数据库绑定数据源的方式。
https://blog.csdn.net/qq_43026206/article/details/86706431
string sql = "select id as 序号, userid as 用户,type as 实验类型,mixrate as 混合比例,initemp as 初始温度,testemp as 测试温度,inipress as 初始压力,testpress as 测试压力,result as 测试结果,datetime as 测试时间 FROM gas_charact";
DataSet dataSet = dbhelper.Select(sql);
dataGridView1.DataSource = dataSet.Tables[0];
this.dataGridView1.Columns[0].Width = 70;
this.dataGridView1.Columns[1].Width = 70;
this.dataGridView1.Columns[2].Width = 160;
for (int i = 3; i < this.dataGridView1.Columns.Count - 1; i++)
{
this.dataGridView1.Columns[i].Width = 76;
}
this.dataGridView1.Columns[this.dataGridView1.Columns.Count - 1].Width = 160;
public DataSet Select(string sql)
{
string[] s = sql.Trim().Split(' ');
MySqlConnection mycon = new MySqlConnection(connectionString);
try
{
if (mycon != null)
{
mycon.Open();
}
MySqlCommand sqlCmd = new MySqlCommand(sql, mycon);
MySqlDataAdapter sda = new MySqlDataAdapter(sqlCmd);
DataSet ds = new DataSet();
sda.Fill(ds, s[3]);
return ds;
}
catch (Exception exception)
{
throw new Exception("SelectMethod:" + exception.Message);
}
finally
{
mycon.Close();
}
}
在DataSet中获取数据:
调整列自适应宽度
https://www.cnblogs.com/wolf-sun/p/3480104.html
https://www.python100.com/html/Y98IOZQ701R2.html
c#datetimepicker控件
显示日期中的年份;显示日期中的月份;显示日期中的日;
https://zhidao.baidu.com/question/1836115590542121300.html
如:条件查询,两个日期之间的所有数据。
string start = DataTimeStart.Value.Year.ToString()+"-"+DataTimeStart.Value.Month.ToString()+"-"+DataTimeStart.Value.Day.ToString()+" 00:00:00";
string end = DataTimeEnd.Value.Year.ToString() + "-" + DataTimeEnd.Value.Month.ToString() + "-" + DataTimeEnd.Value.Day.ToString() + " 23:59:59"; ;
string sql = "select id as 序号, userid as 用户,type as 实验类型,mixrate as 混合比例,initemp as 初始温度,testemp as 测试温度,inipress as 初始压力,testpress as 测试压力,result as 测试结果,datetime as 测试时间 FROM gas_charact WHERE datetime BETWEEN '" + start+"' and '"+ end+"'";
DataSet dataSet = dbhelper.Select(sql);
dataGridView1.DataSource = dataSet.Tables[0];
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现