asp.net 连接orcle 数据库实例

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OracleClient;
//using System.Data.OleDb;


public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        string connectionString;
        string queryString;

        connectionString = "Data Source=172.11.11.11/gs;User ID=sssss;PassWord=888888";

        queryString = "SELECT * FROM ZWKMZD211016 where zwkmzd_kmbh = 24101";

        OracleConnection myConnection = new OracleConnection(connectionString);

        OracleCommand myORACCommand = myConnection.CreateCommand();

        myORACCommand.CommandText = queryString;

        myConnection.Open();

        OracleDataReader myDataReader = myORACCommand.ExecuteReader();

        //myDataReader.Read();


        Response.Write("<h3>使用SqlDataReader对象查询数据库</h3>");
        Response.Write("<table border=1 cellspacing=0 cellpadding=2>");
        Response.Write("<tr bgcolor=yellow>");
        for (int i = 0; i < myDataReader.FieldCount; i++)
        {
            Response.Write("<td>" + myDataReader.GetName(i) + "</td>");
        }
        Response.Write("</tr>");
        while (myDataReader.Read())
        {
            Response.Write("<tr>");
            for (int i = 0; i < myDataReader.FieldCount; i++)
            {
                Response.Write("<td>" + myDataReader[i].ToString() + "</td>");
            }
            Response.Write("</tr>");
        }
        Response.Write("</table>");

        myDataReader.Close();

        myConnection.Close();


    }
}

相关内容推荐