zoukankan      html  css  js  c++  java
  • C# gridview绑定oracle

    两种方式,都通过测试。

     一、CS代码

    View Code
     1 namespace zbjjSms.test
     2 {
     3     public partial class ts2db : System.Web.UI.Page
     4     {
     5         static string constr = "Host=192.168.1.106;Port=1521;User ID=xch;Password=xch; SID=orcl;LicensePath=H:\\xchPrj\\zbjjsms\\zbjjSms\\DDTek.lic";
     6         protected void Page_Load(object sender, EventArgs e)
     7         {
     8             OracleConnection cn = new OracleConnection(constr);//("Data Source=orcl;User Id=xch;Password=xch;LicensePath=H:\\xchPrj\\zbjjsms\\zbjjSms\\DDTek.lic");
     9                 cn.Open();
    10                 OracleCommand cmd = new OracleCommand("SELECT * from SMS_GROUP",cn);
    11                 
    12                     this.GridView1.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection);
    13                     this.GridView1.DataBind();
    14                 
    15         }
    16     }
    17 }

    二、CS代码

    View Code
     1     public partial class databaseTest : System.Web.UI.Page
     2     {
     3        static string constr = "Host=192.168.1.106;Port=1521;User ID=xch;Password=xch; SID=orcl;LicensePath=H:\\xchPrj\\zbjjsms\\zbjjSms\\DDTek.lic";
     4        string sql = "select * from SMS_GROUP";
     5         //OracleHelper conDB = new OracleHelper(constr);
     6 
     7         protected void Page_Load(object sender, EventArgs e)
     8 
     9         {
    10             try
    11             {
    12                 OracleHelper conDB = new OracleHelper(constr);
    13               
    14                 DataSet testds = conDB.Query(sql);
    15 
    16                 this.GridView1.DataSource = testds.Tables[0];
    17                 
    18                 this.GridView1.DataBind();
    19 
    20                 //foreach (DataRow row in testds.Tables[0].Rows)
    21                 //{
    22                 //    // this.ywbh.Items.Add(new ListItem(row["YWMC"].ToString(), row["YWBH"].ToString()));
    23                 //    // ListBox1.Text = row["yhdh"].ToString();
    24                 //    Label1.Text += row[0].ToString();
    25                 //}
    26                
    27             }
    28             catch (Exception ex)
    29             {
    30                // ListBox1.Items.Add(ex.ToString());
    31                 TextBox1.Text = ex.ToString();
    32             }
  • 相关阅读:
    序列化实现 深拷贝
    为边框应用图片 border-image
    阴影 box-shadow(二)
    阴影 box-shadow(一)
    css3之圆角效果 border-radius
    文档对象模型(DOM)
    Cookie/Session机制详解
    PHP错误The server encountered an internal error or misconfiguration and was unable to complete your re
    关于js with语句的一些理解
    使用JavaScript+Html创建win8应用(二)
  • 原文地址:https://www.cnblogs.com/xuchanghua/p/2724399.html
Copyright © 2011-2022 走看看