说明:我这个程序是在ORACLE 8.1.5 上的,不保证你的就可以使用,你这个要配置一下ODBC,
本机的程序最主要的问题可能是如下:
dim MyConn as OleDbConnection = new OleDbConnection _
("Provider=MSDAORA.1;Password=tiger;User ID=scott;Data Source=oracle;PeadoRSist Security Info=True")
全部的程序如下:
<%@ Page aspcompat=true Debug="true" Language = "VB" %>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb" %><!
This example uses ADO to read records from a database and print two
fields from all records in the database to an ASP.NET page.
The database is located on the server and connection is through an ODBC system data source (DSN).
><script runat="server">'<This example uses ADO to read records from a database and print two
'fields from all records in the database to an ASP.NET page.
'The database is located on the server and connection is through an ODBC system data source (DSN).>sub Page_Load(obj as object,e as eventargs)
dim MyConn as OleDbConnection = new OleDbConnection _
("Provider=MSDAORA.1;Password=tiger;User ID=scott;Data Source=oracle;PeadoRSist Security Info=True")
dim MyCommand as OleDbDataAdapter = New OleDbDataAdapter _
("SELECT EmpNo,eName,Job,HireDate,Sal,MGR,DName,loc FROM emp,dept where dept.deptno=emp.deptno",MyConn)
dim ds as dataset = new Dataset()
MyCommand.Fill(ds,"emp")
datagrid1.datasource=ds
datagrid1.databind()
' databind()
end sub
</script>
<html><body>
<asp:datagrid id="datagrid1" runat="server"
BorderColor="Black"
GridLines="Vertical"
cellpadding="4"
cellspacing="0"
width="900"
Font-Name="Arial"
Font-Size="8pt"
ShowFooter="True"
HeaderStyle-Backcolor="#cccc99"
FooterStyle-BackColor="#cccc99"
ItemStyle-backcolor="#cccccc"
AutoGenerateColumns = "false" >
<Columns>
<asp:TemplateColumn HeaderText="EmpNo">
<ItemTemplate>
<asp:Label id="lblempno" runat="server"
Text='<%#Container.DataItem("EmpNo")%>'/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="Ename"
datafield="Ename"/>
<asp:BoundColumn HeaderText="Dname"
datafield="Dname"/>
<asp:BoundColumn HeaderText="Loc"
datafield="loc"/>
<asp:BoundColumn HeaderText="HireDate"
datafield="HireDate"/>
<asp:BoundColumn HeaderText="sal"
datafield="sal"/>
<asp:HyperlinkColumn HeaderText="Edit" Text="Edit"
NavigateURL="http:\\www.sina.com.cn" />
<asp:ButtonColumn HeaderText="Delete?" Text="x"
CommandName="delete" ButtonType="PushButton" />
</Columns>
</asp:datagrid>
</html></body>
本机的程序最主要的问题可能是如下:
dim MyConn as OleDbConnection = new OleDbConnection _
("Provider=MSDAORA.1;Password=tiger;User ID=scott;Data Source=oracle;PeadoRSist Security Info=True")
全部的程序如下:
<%@ Page aspcompat=true Debug="true" Language = "VB" %>
<%@ Import Namespace="System.Data"%>
<%@ Import Namespace="System.Data.OleDb" %><!
This example uses ADO to read records from a database and print two
fields from all records in the database to an ASP.NET page.
The database is located on the server and connection is through an ODBC system data source (DSN).
><script runat="server">'<This example uses ADO to read records from a database and print two
'fields from all records in the database to an ASP.NET page.
'The database is located on the server and connection is through an ODBC system data source (DSN).>sub Page_Load(obj as object,e as eventargs)
dim MyConn as OleDbConnection = new OleDbConnection _
("Provider=MSDAORA.1;Password=tiger;User ID=scott;Data Source=oracle;PeadoRSist Security Info=True")
dim MyCommand as OleDbDataAdapter = New OleDbDataAdapter _
("SELECT EmpNo,eName,Job,HireDate,Sal,MGR,DName,loc FROM emp,dept where dept.deptno=emp.deptno",MyConn)
dim ds as dataset = new Dataset()
MyCommand.Fill(ds,"emp")
datagrid1.datasource=ds
datagrid1.databind()
' databind()
end sub
</script>
<html><body>
<asp:datagrid id="datagrid1" runat="server"
BorderColor="Black"
GridLines="Vertical"
cellpadding="4"
cellspacing="0"
width="900"
Font-Name="Arial"
Font-Size="8pt"
ShowFooter="True"
HeaderStyle-Backcolor="#cccc99"
FooterStyle-BackColor="#cccc99"
ItemStyle-backcolor="#cccccc"
AutoGenerateColumns = "false" >
<Columns>
<asp:TemplateColumn HeaderText="EmpNo">
<ItemTemplate>
<asp:Label id="lblempno" runat="server"
Text='<%#Container.DataItem("EmpNo")%>'/>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn HeaderText="Ename"
datafield="Ename"/>
<asp:BoundColumn HeaderText="Dname"
datafield="Dname"/>
<asp:BoundColumn HeaderText="Loc"
datafield="loc"/>
<asp:BoundColumn HeaderText="HireDate"
datafield="HireDate"/>
<asp:BoundColumn HeaderText="sal"
datafield="sal"/>
<asp:HyperlinkColumn HeaderText="Edit" Text="Edit"
NavigateURL="http:\\www.sina.com.cn" />
<asp:ButtonColumn HeaderText="Delete?" Text="x"
CommandName="delete" ButtonType="PushButton" />
</Columns>
</asp:datagrid>
</html></body>
解决方案 »
- asp.net前台页面中怎样绑定值
- asp:label限定大小以后如果文字过多会不会自动出滚动条?
- 层里面的button怎么加事件啊!
- document.getElementById lable 接收传值 急急急
- 散分30请教提交数据库问题!!
- 如何遍历一个Web应用中的所有Session对象
- 关于 “超时时间已到。在从池中获取连接之前超时时间已过。出现这种情况可能是因为所有池连接都已被使用并已达到最大池大小。”的问题
- IhttpHandler+server.execute+session问题
- 请教!!sql写法,请各位帮忙......
- 系统内:如何实现群发短消息
- infragistics 控件谁用过?
- 关于crystal打印问题
ConStr+="Data Source=" & Server.MapPath("YANGZUJIAN.mdb")中要填的oracle数据库地址是这样写吗?它的后缀名是.mdb吗?
还有,程序老提示这句出错: Da.Fill(Ds, "ORDERS")
是那里错了???
我建立的服务名是orawg,以下代码在 vs2002/oracle 9i/win xp 测试通过,
至于oracle 客户端,你可以到otn.oracle.com 上下载 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
Dim connStr As String = "Provider=MSDAORA.1;Password=tiger;User ID=scott;Data Source=orawg"
Dim objConnection As New OleDb.OleDbConnection(connStr)
objConnection.Open() Dim strSql As String = "select * from emp"
Dim adapter As New System.Data.OleDb.OleDbDataAdapter(strSql, objConnection)
Dim ds As New DataSet()
adapter.Fill(ds, "Emp")
objConnection.Close() With dgOracle
.DataSource = ds.Tables("Emp")
.DataBind()
End With End Sub
====================
<add key="OracleConn" value="Provider=MSDAORA.1;Password=credit;User ID=system;Data Source=tuhasbk;Persist Security Info=True" />
====================
后台代码这样写(.vb):
import system.configuration
....
Dim Conn as String
Conn = configurationsettings.appsettings("OracleConn")
SBGLConn = New OleDbConnection(Conn)
........
系统安装有oracle服务器(以前安装有oracle客户端,不是oracle服务器,也可以顺利执行)
====================
希望共同学习——msn: [email protected]
在framework1.1
http://www.dotnetjohn.com/articles/articleid35.aspx?id=35