数据访问层代码你会写吗?string sql="select * from table where name="+'"TextBox.Text"';DataSet ds=Fill(sql); GridView.DataSource=ds;GridView.DataBind(); Fill方法是个查询方法 你自己写个就是了
string sql = "select * from表明 where 条件 order by DemandNum desc"; DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.conStr, CommandType.Text, sql, null); this.GridView.DataSource = ds .Tables[0]; this.GridView.DataBind();
private void GetData(string selectCommand) { try { String connectionString = "Integrated Security=SSPI;Persist Security Info=False;" + "Initial Catalog=Northwind;Data Source=localhost"; dataAdapter = new SqlDataAdapter(selectCommand, connectionString); SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter); DataTable table = new DataTable(); table.Locale = System.Globalization.CultureInfo.InvariantCulture; dataAdapter.Fill(table); bindingSource1.DataSource = table; dataGridView1.AutoResizeColumns( DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader); } catch (SqlException) { MessageBox.Show("To run this example, replace the value of the " + "connectionString variable with a connection string that is " + "valid for your system."); } }
GridView.DataSource=ds;GridView.DataBind();
Fill方法是个查询方法 你自己写个就是了
DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.conStr, CommandType.Text, sql, null);
this.GridView.DataSource = ds .Tables[0];
this.GridView.DataBind();
{
try
{
String connectionString =
"Integrated Security=SSPI;Persist Security Info=False;" +
"Initial Catalog=Northwind;Data Source=localhost";
dataAdapter = new SqlDataAdapter(selectCommand, connectionString); SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter); DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
dataAdapter.Fill(table);
bindingSource1.DataSource = table; dataGridView1.AutoResizeColumns(
DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
}
catch (SqlException)
{
MessageBox.Show("To run this example, replace the value of the " +
"connectionString variable with a connection string that is " +
"valid for your system.");
}
}