protected void BindtoDataGrid()
...{
string sql=@"";//blog.csdn.Net/jbgh608
string ssql=@"";
DataSet ds = new DataSet();
DataTable tb=new DataTable();
tb=GetDataTable(sql);
tb.TableName="記錄";
ds.Tables.Add(tb);
tb=null;
tb=GetDataTable(ssql);
tb.TableName="明細記錄";
ds.Tables.Add(tb);
tb=null;
ds.Relations.Add("明細",ds.Tables["記錄"].Columns["id"],
ds.Tables["記錄"].Columns["id"]);
dataGrid1.SetDataBinding(ds,"記錄");
dataGrid2.DataSource=dataGrid1.DataSource;
}
public static DataTable GetDataTable(string commandText)
...{
string connection ="server=ORADB;uid=jbgh608;pwd=jbgh608;";
OracleConnection con = new OracleConnection(connection);
OracleCommand cmd=new OracleCommand(commandText,con);
OracleDataAdapter adapter = new OracleDataAdapter(cmd);
try
...{
DataTable dt=new DataTable();
adapter.Fill(dt);
return dt;
}
catch(Exception err)
...{
throw new Exception(err.Message);
}
finally
...{
cmd.Dispose();
cmd=null;
adapter.Dispose();
adapter=null;
}
}