如何填充用C#的数据集从Oracle数据库数据库、数据、Oracle

2023-09-03 03:09:38 作者:对不起未必能换来没关系

我试图填补了oracle的数据集== NULL;

i am trying to fill the oracle dataset== NULL;

我用它与.NET框架2.0用C#

i am using it with a .net framework 2.0 with C#

推荐答案

下面是一个例子System.Data.OracleClient的 http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oracledataadapter%28v=vs.71%29.aspx (本例中为1.1,但将努力同2.0)

here is a system.data.oracleclient example http://msdn.microsoft.com/en-us/library/system.data.oracleclient.oracledataadapter%28v=vs.71%29.aspx (this example is 1.1 but will work the same with 2.0)

(从链接片段)

OracleConnection conn = new OracleConnection("Data Source=Oracle8i;Integrated Security=yes");
Conn.Open;
OracleCommand cmd = conn.CreateCommand();
cmd.CommandText = "sp_pkg.getdata";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new OracleParameter("a1", OracleType.Cursor)).Direction = ParameterDirection.Output;
cmd.Parameters.Add(new OracleParameter("a2", OracleType.Cursor)).Direction = ParameterDirection.Output;
DataSet ds = new DataSet();
OracleDataAdapter adapter = new OracleDataAdapter(cmd);
adapter.Fill(ds);

下面是一个ODP(推荐)例如: http://www.oracle.com/technology/sample_$c$c/tech/windows/odpnet/DSPopulate/ViewProducts.cs.html

here is an ODP (recommended) example: http://www.oracle.com/technology/sample_code/tech/windows/odpnet/DSPopulate/ViewProducts.cs.html

(从链接片段)

//Instantiate OracleDataAdapter to create DataSet
productsAdapter = new OracleDataAdapter();

//Fetch Product Details
productsAdapter.SelectCommand = new OracleCommand("SELECT " +
                                                  "Product_ID , " +
                                                  "Product_Name , " +
                                                  "Product_Desc , " +
                                                  "Category, " +
                                                  "Price " +
                                                  "FROM Products",conn);

//Instantiate DataSet object
productsDataSet = new DataSet("productsDataSet");

//Fill the DataSet with data from 'Products' database table
productsAdapter.Fill(productsDataSet, "Products");

//setting 'productsDataSet' as  the datasouce and 'Products' table
//as the table to which the 'productsDataGrid' is Bound.
productsDataGrid.SetDataBinding(productsDataSet,"Products"); 
 
精彩推荐
图片推荐