用DATASET吧!例子:
myConnection = new System.Data.SqlClient.SqlConnection
(System.Configuration.ConfigurationSettings.AppSettings["connectionstring"]);
myConnection.Open(); myDataSet = new System.Data.DataSet();
myDataSet.CaseSensitive = true; myCommand = new System.Data.SqlClient.SqlCommand();
myCommand.Connection = myConnection; myCommand.CommandText = "Select ptf_ptfinfo.cptf_no as PTF编号," +
"ptf_system.csys_cname as 系统名称," +
"ptf_ptfinfo.cptf_manager as 负责人," +
"convert(char(10),ptf_ptfinfo.dptf_testsend,120) as 发送测试日期," +
"convert(char(10),ptf_ptfinfo.dptf_testend,120) as 要求测毕日期," +
"ptf_level.cptf_levelname as 紧急程度," +
"ptf_state.cptf_statename as 状态" +
" from ptf_ptfinfo,ptf_level,ptf_state,ptf_system" +
" where ptf_ptfinfo.cptf_level = ptf_level.cptf_level" +
" and ptf_ptfinfo.csys_no = ptf_system.csys_no" +
" and ptf_ptfinfo.cptf_state = ptf_state.cptf_state" +
" and ptf_ptfinfo.cptf_state <> '0'" +
" and ptf_ptfinfo.cptf_state <> '4'" +
" order by ptf_ptfinfo.cptf_no"; dataAdapter = new System.Data.SqlClient.SqlDataAdapter();
dataAdapter.SelectCommand = myCommand;
dataAdapter.TableMappings.Add("Table","ptf_ptfinfo");
dataAdapter.Fill(myDataSet); DataGrid_undispose.DataSource = myDataSet.Tables["ptf_ptfinfo"].DefaultView;
DataGrid_undispose.DataBind();
myConnection = new System.Data.SqlClient.SqlConnection
(System.Configuration.ConfigurationSettings.AppSettings["connectionstring"]);
myConnection.Open(); myDataSet = new System.Data.DataSet();
myDataSet.CaseSensitive = true; myCommand = new System.Data.SqlClient.SqlCommand();
myCommand.Connection = myConnection; myCommand.CommandText = "Select ptf_ptfinfo.cptf_no as PTF编号," +
"ptf_system.csys_cname as 系统名称," +
"ptf_ptfinfo.cptf_manager as 负责人," +
"convert(char(10),ptf_ptfinfo.dptf_testsend,120) as 发送测试日期," +
"convert(char(10),ptf_ptfinfo.dptf_testend,120) as 要求测毕日期," +
"ptf_level.cptf_levelname as 紧急程度," +
"ptf_state.cptf_statename as 状态" +
" from ptf_ptfinfo,ptf_level,ptf_state,ptf_system" +
" where ptf_ptfinfo.cptf_level = ptf_level.cptf_level" +
" and ptf_ptfinfo.csys_no = ptf_system.csys_no" +
" and ptf_ptfinfo.cptf_state = ptf_state.cptf_state" +
" and ptf_ptfinfo.cptf_state <> '0'" +
" and ptf_ptfinfo.cptf_state <> '4'" +
" order by ptf_ptfinfo.cptf_no"; dataAdapter = new System.Data.SqlClient.SqlDataAdapter();
dataAdapter.SelectCommand = myCommand;
dataAdapter.TableMappings.Add("Table","ptf_ptfinfo");
dataAdapter.Fill(myDataSet); DataGrid_undispose.DataSource = myDataSet.Tables["ptf_ptfinfo"].DefaultView;
DataGrid_undispose.DataBind();
string sproc = "fetch_subjects_of_asset";
//过程名fetch_subjects_of_asset
SqlCommand oCommand = new SqlCommand(sproc);
oCommand.CommandType = CommandType.StoredProcedure;
SqlParameter p1 = new SqlParameter("@asset_id", SqlDbType.Int, 4);
//输入参数asset_id
p1.Value = assetID;
oCommand.Parameters.Add(p1);SqlConnection oConnection = new SqlConnection(connectionString);
oCommand.Connection = oConnection;
SqlDataAdapter oData = new SqlDataAdapter(oCommand);
DataSet oDataSet = new DataSet();
oData.Fill(oDataSet);
//数据就取出来了,放在oDataSet
string sproc = "fetch_subjects_of_asset";
//过程名fetch_subjects_of_asset
SqlCommand oCommand = new SqlCommand(sproc);
oCommand.CommandType = CommandType.StoredProcedure;
SqlParameter p1 = new SqlParameter("@asset_id", SqlDbType.Int, 4);
//输入参数asset_id
p1.Value = assetID;
oCommand.Parameters.Add(p1);SqlConnection oConnection = new SqlConnection(connectionString);
oCommand.Connection = oConnection;
SqlDataAdapter oData = new SqlDataAdapter(oCommand);
DataSet oDataSet = new DataSet();
oData.Fill(oDataSet);
//数据就取出来了,放在oDataSet