请教一下winForm里datagrid的使用方法 刚刚开始学C#,看了vs.net的msdn中的帮助还是一头雾水,请教高手指点dataGrid的基本原理与简单的用法。比如说。如何绑定一个数据表、如果用编程的方法显示查询的数据!如何显示SQL查询的数据等。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 http://community.csdn.net/Expert/FAQ/List_Room_FAQ_Index.asp?Roomid=5201超级多 using System.Data;using System.Windows.Forms;using System.Data.SqlClient;public class Test : Form{ string strConn = "server=localhost;database=Northwind;uid=sa;pwd=mypassword"; string strSql = "SELECT * FROM Employees"; // 构造函数 Test() { DataGrid dg = new DataGrid(); dg.Parent = this; dg.Dock = DockStyle.Fill; dg.DataSource = DtQuery(strSql, strConn); } // 执行SQL语句,将结果返回到数据表中。 public DataTable DtQuery(string strSql, string strConn) { SqlConnection conn = new SqlConnection(strConn); SqlDataAdapter apt = new SqlDataAdapter(strSql, conn); DataTable dt = new DataTable(); apt.Fill(dt); return dt; } // 程序入口 static void Main() { Application.Run(new Test()); }} 求QQ登陆网页的原理 在没有任何数据时进行无效的读取尝试。 关于SQL语句的筛选排序问题 在c#里如何用代碼在datagridview里某列變為checkbox ? winform窗体如何分多次加载数据到数据窗格? 绘制椭圆形和矩形,定义颜色!!急 跪求带参数传递的报表制作方法 求救:DataGridView在编辑状态按回车有没有办法跳到右边一格? 数据乱码问题,在线等~~~ web服务返回纪录集调用的问题,解决立即给分! 以类为成员的数组碰到的问题, 请问如何禁止拖动窗口?
超级多
using System.Windows.Forms;
using System.Data.SqlClient;public class Test : Form
{
string strConn = "server=localhost;database=Northwind;uid=sa;pwd=mypassword";
string strSql = "SELECT * FROM Employees"; // 构造函数
Test()
{
DataGrid dg = new DataGrid();
dg.Parent = this;
dg.Dock = DockStyle.Fill;
dg.DataSource = DtQuery(strSql, strConn);
} // 执行SQL语句,将结果返回到数据表中。
public DataTable DtQuery(string strSql, string strConn)
{
SqlConnection conn = new SqlConnection(strConn);
SqlDataAdapter apt = new SqlDataAdapter(strSql, conn);
DataTable dt = new DataTable();
apt.Fill(dt);
return dt;
} // 程序入口
static void Main()
{
Application.Run(new Test());
}
}