c#读出Oracle数据库用户表结构

///先引入Oracle.DataAccess.dll文件的命名空间
using Oracle;

using Oracle.DataAccess;

using Oracle.DataAccess.Client;

 
class Test

    {

        private const string SqlStr = "select * from Table_Name Where Rownum<2";

        private void But_WriteToXml(object sender, EventArgs e)

        {

            try

            {

                ///创建连接字符串

                string ConnectionString10GUp = "Data Source=q103; User Id=jtdata; Password=jtdata"; //此连接方式是10G、或11G的连接方法。

                string ConnectionString10GD = "Data Source=q103;Persist Security Info=True;User ID=jtdata;Password=jtdata";//此为10G以下。

                OracleConnection conn = new OracleConnection(ConnectionString10GD);

                OracleCommand cmd = new OracleCommand(SqlStr, conn);

                DataSet ds = new DataSet();

                OracleDataAdapter oda = new OracleDataAdapter(cmd);

                oda.Fill(ds, "Table");

                ds.WriteXml("jtdata.xml", XmlWriteMode.WriteSchema);

                MessageBox.Show("Write To Xml Succeed");

            }

            catch (Exception ex)

            { MessageBox.Show(ex.Message); }

        }
 
 
//DbProviderFactory fa = DbProviderFactories.GetFactory("Oracle.DataAccess.Client");

                //DbConnection con = fa.CreateConnection();

                //con.ConnectionString = ConnectionString;

                //DbCommand dbc = con.CreateCommand();

                //dbc.CommandText = "select * from JT_X_KHDDMX where rownum<2";

                //DbDataAdapter ada = fa.CreateDataAdapter();

                //ada.SelectCommand = dbc;

                //DataSet ds = new DataSet();

                //ada.Fill(ds);

                //ds.WriteXml("txt.xml", XmlWriteMode.WriteSchema);

                //Console.WriteLine("读取完成");

 

    }

你可能感兴趣的:(oracle数据库)