采用三层架构的模式,在Datagridview中显示users表中的所有信息!急!!!
C#中如何显示在Datagridview中显示users表中的所有信息,最好是三层架构模式!
- 提问者网友:十年饮冰
- 2021-06-04 18:37
- 五星知识达人网友:爱难随人意
- 2021-06-04 19:51
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Server=WWW-2270B8786BB;Integrated Security=SSPI;Database=Northwind;Uid=sa;Pwd=sa;");
string sqlStr = "select * from Orders";
SqlCommand cmd = new SqlCommand(sqlStr, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0];
}
- 1楼网友:酒者煙囻
- 2021-06-04 20:58
sqlHelp层 public DataSet GetDs(string sqlText) { OpenConnection(); SqlDataAdapter sda = new SqlDataAdapter(sqlText, con); DataSet ds = new DataSet(); sda.Fill(ds); CloseConnection(); return ds; }
dal层 public DataSet show1() { string sql = "select *from users"; return help.GetDs(sql); }
bll层 public DataTable ShowInfo() { return dal.show1().Tables[0]; }
UI 直接调用BLL绑定