你好,在CS文件中把下面的函数添加进去:
///
/// 运行查询语句,返回DataSet对象
///
/// 查询语句
/// 要保存的表名称
///
public DataSet GetDataSet(string strSql, string tableName)
{
SqlConnection conn = GetConnection();
SqlDataAdapter da;
DataSet ds;
try
{
da = new SqlDataAdapter(strSql, conn);
ds = new DataSet();
da.Fill(ds, tableName);
}
catch
{
throw;
}
finally
{
CloseConn(conn);
}
return ds;
}
你的代码的修改:
.....
SqlCommand sqlc_FOsearchall = new SqlCommand(SQL_FOsearchall, B_FO_Conn);
DataSet ds = GetDataSet(sqlc_FOsearchall,"表名"); // 表名你修改为对应的表名
Grid_FO.DataSource = ds.Tables["表名"];
B_FO_Conn.Close();
ExecuteNonQuery()// 这个是返回受影响的行数.
查询语句,有返回值的就用 ExecuteReader();
没有返回值就用ExecuteDataSet();
查询换之后,GridView.DataSource = 查询完的结果;
GridView.DataBind();
DataSet ds =new DataSet();
string ConnString= "Server=10.85.51.22;database=fsmms;uid=fsmms_admin;pwd=fsmms@sda";
using(SqlConnection B_FO_Conn = new SqlConnection(ConnString))
{
B_FO_Conn.Open();
string SQL_FOsearchall = @"SELECT * FROM [LeeOrderParts]";
SqlDataAdapter command = new SqlDataAdapte(SQL_FOsearchall,B_FO_Conn);
command.Fill(ds, "ds");
}
Grid_FO.DataSource =ds.Tables[0];
Grid_FO.DataBind();
SqlDataAdapter da=new SqlDataAdapter ();
DataSet ds=new DataSet();
string ConnString = "Server=10.85.51.22;database=fsmms;uid=fsmms_admin;pwd=fsmms@sda";
SqlConnection cn= new SqlConnection(ConnString);
cn.Open();
SqlCommand cm= new SqlCommand("查询语句", cn);
da.selct..=cm
da.Fell(ds,"表名");
this.Gridview1.DataSource =ds.table["表名"];