易截截图软件、单文件、免安装、纯绿色、仅160KB

ASP.NET2.0连接ORACLE解决方案

界面: Default.aspx
 
界面上添加的控件:
两个TextBox: tEmail(用于输入用户email),tPassword(用于输入注册密码)
一个Button: bReg
一个Label: lLable(用于注册成功后显示应答)
Demo的代码: Default.aspx.cs
我们先把数据的连接字符串写在Web.config里:
<appSettings>
<add key="oracleconn" value="User ID=用户名;Password=密码;Data Source=数据库服务名;"/>
</appSettings>
下面是Demo的源代码:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OracleClient; //添加OracleClient的引用
public partial class _Default : System.Web.UI.Page
{
public System.Data.OracleClient.OracleConnection objConn; //声明一个OracleConnection对象
public System.Data.OracleClient.OracleCommand objCmd; //声明一个OracleCommand对象
protected void Page_Load(object sender, EventArgs e)
{
lLable.Text = "";
string strcon = System.Configuration.ConfigurationManager.AppSettings["oracleconn"];
//从Web.config 文件里调用数据库连接字符串
objConn = new OracleConnection(strcon);
}
protected void bReg_Click(object sender, EventArgs e)
{
string strSQL = "INSERT INTO TEMP(EMAIL,PASSWORD) values ('";
strSQL+=tEmail.Text.Replace("'","''").ToString()+"','";
strSQL+=tPassword.Text.Replace("'","''").ToString()+"')";
objCmd = new OracleCommand(strSQL, objConn);
objConn.Open();
objCmd.ExecuteNonQuery();
objConn.Close();
lLable.Text = "注册成功,您的邮件地址是:"+tEmail.Text.ToString();
}
}
注意:
其实直接写上面的代码会出不少错误的,要做两个工作才可以。
1. ASP.NET2.0里默认不能直接添加using System.Data.OracleClient;需要在填加引用的.NET组件框里选择System.Data.OracleClient添加后才能用。
2. 在ASP.NET1.1中调用Web.config中的数据库连接字符串时使用语句System.Configuration.ConfigurationSettings.AppSettings["oracle"];,在2.0里须要使用System.Configuration.ConfigurationManager.AppSettings


相关文档:

Oracle主键自动增长

Oracle主键自动增长
这几天搞Oracle,想让表的主键实现自动增长,查网络实现如下:
create table simon_example
(
  id number(4) not null primary key,
  name varchar2(25)
)
-- 建立序列:
-- Create sequence
create sequence SIMON_SEQUENCE        &nb ......

Oracle日期函数:

 select sysdate from dual; 从伪表查系统时间,以默认格式输出。
sysdate+(5/24/60/60) 在系统时间基础上延迟5秒
sysdate+5/24/60 在系统时间基础上延迟5分钟
sysdate+5/24 在系统时间基础上延迟5小时
sysdate+5 在系统时间基础上延迟5天
所以日期计算默认单位是天
round (sysdate,’day’) 不是四除 ......

ORACLE Top/Bottom N、First/Last、NTile

目录
==================================================================
1.带空值的排列
2.Top/Bottom N查询
3.First/Last排名查询
4.按层次查询
一、带空值的排列:
假如被排列的数据中含有空值呢?
SQL> select region_id, customer_id,
   2         ......

什么是ASP.NET

 What is ASP.NET
ASP.NET is a unified Web development model that includes the services necessary for you to build enterprise-class Web applications with a minimum of coding. ASP.NET is part of the .NET Framework, and when coding ASP.NET applications you have access to classes in the .NET Frame ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号