开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 3188|回复: 0

[源码] .net通过Odbc操作Sybase

[复制链接]

0

精华

100

贡献

33

赞扬

帖子
132
软币
3320
在线时间
53 小时
注册时间
2013-8-31
发表于 2013-9-2 22:02:02 | 显示全部楼层 |阅读模式
web.config里面的配置
<connectionStrings>
  <add name="qxzb" connectionString="prodiver={Sybase ASE ODBC Driver};dsn=qxzb;uid=dba;pwd=sql"/>
  </connectionStrings>

网页前台代码
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:GridView ID="GridView1" runat="server">
        </asp:GridView>
   
    </div>
    </form>
</body>
</html>


网页后台代码
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Odbc;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        OdbcConnection con = new OdbcConnection(ConfigurationManager.ConnectionStrings["qxzb"].ConnectionString.ToString());
        try
        {
            con.Open();
            OdbcCommand cmd = new OdbcCommand("select * from qxzb order by id",con);
            OdbcDataReader rd = cmd.ExecuteReader();
            this.GridView1.DataSource = rd;
            this.GridView1.DataBind();
            con.Close();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);

        }
    }
}

回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-5-21 00:19

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表