using System.Data;
using System.Data.SqlClient;
string SqlCon=" "; // 连接数据库
string SqlStr=" "; //查询语句
SqlConnection conn=new SqlConnection(SqlCon);
SqlDataAdapter adapter=new SqlDataAdapter(SqlStr,conn);
SqlCommandBuilder cb=new SqlCommandBuilder(adapter);
DataSet ds=new DataSet();
adapter.Fill(ds,"table");
DataGrid1.SetDataBinding(ds,"table");
能用T-SQL实现的功能,尽量交给SQL去做,尽量减少用户界面与数据的交换.
编程时尽量以最简单最实用的方式去实现,先在实用的基础上才去创新