显示数据的查询
1.创建查询界面
2.双击查询全部 添加查询方法
//查询全部
private void btnQuery_Click(object sender, EventArgs e)
{
string sql = "select * from SeQu ";
SqlCeDataReader objReader = SQLHelper.GetReader(sql);
List list = new List();
while (objReader.Read())
{
list.Add(new SeQuDate()
{
SqId = objReader["sqid"].ToString(),
SqName = objReader["sqname"].ToString(),
SqManer = objReader["sqmaner"].ToString(),
SqPhone = objReader["sqphone"].ToString(),
SqTime = Convert.ToDateTime(objReader["sqtime"])
});
}
objReader.Close();
this.dgvStudentList.AutoGenerateColumns = false;//禁止生成不需要的列
this.dgvStudentList.DataSource = list;
}
//这里说一下 SeQuDate 是我创建的一个社区实体类 对应 sql server数据库SeQu表的信息
sql server数据库SeQu表的信息:
SeQuDate 是我创建的一个社区实体类
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Models
{
///
/// 社区实体类
///
public class SeQuDate
{
public string SqId { get; set; }
public string SqName { get; set; }
public string SqManer { get; set; }
//将数据库中的18位整数转换成字符串
public string SqPhone { get; set; }
public DateTime SqTime { get; set; }
}
}
然后 特别要注意 : this.dgvStudentList 就是我的DataGridView.
然后编辑列 ,不然现在是接受不到数据的
然后 一定要记得修改datepropertyName对应数据库列的名称
效果:
然后 按照社区名称 或者社区负责人查询 只需要修改一下sql语句 加where判断就好了,
string sql = "select * from SeQu where SeQu.sqname='" + name + "'";
Sql Server 常用语句:https://blog.csdn.net/m0_37583098/article/details/87876264
基本的Sql Server语句还是要懂得。
预祝成功!!!!!!!!!
下一篇 管理开发系统六:winform连接数据库修改
管理系统开发一: winform连接sql数据库 https://blog.csdn.net/m0_37583098/article/details/88546146
管理系统开发二: winforml登录界面sql数据查询和修改 https://blog.csdn.net/m0_37583098/article/details/88547123
管理系统开发三: winforml录入界面 https://blog.csdn.net/m0_37583098/article/details/88547805
管理系统开发四: 在主窗体中嵌入子窗体的实现 https://blog.csdn.net/m0_37583098/article/details/88549151
管理开发系统五:winform连接数据库查询 使用DataGridView展示查询结果 https://blog.csdn.net/m0_37583098/article/details/88549461
管理开发系统六:winform连接数据库修改 https://blog.csdn.net/m0_37583098/article/details/88550157
管理开发系统七:winform连接数据库删除 https://blog.csdn.net/m0_37583098/article/details/88578796
管理开发系统八:winform导出excel https://blog.csdn.net/m0_37583098/article/details/88579043
管理开发系统九:winform带sql数据库导出 https://blog.csdn.net/m0_37583098/article/details/88580311
sql service 常用语句基础https://blog.csdn.net/m0_37583098/article/details/87876264