All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
手工卸载SQL Server 2000数据库_[SQL Server教程]
asp.net2.0网站语法之对象标记语法
C#中删除XML节点实例
模板用xml的思路_php资料_编程技术
Linq,to,SQL,Dynamic,动态查询_[Asp.Net教程]
将SSH与PHP相连接 确保传输数据的安全_[PHP教程]
多种方法实现超长字符用-.....-代替_[Asp.Net教程]
WebService服务和ajax使用教程_.net资料_编程技术
2003 下 IIS+PHP+MySQL+Zend Optimize_[PHP教程]
ASP.NET自动识别GB2312与UTF-8编码的文件_.net资料_编程技术
Reading number is top 10 pictures
Sora aoi in China1
Wear bikinis cock
The mother was a stay-at-home children too tired took three baby suicide
A man's favorite things14
30 beautiful school beauty5
刘亦菲写真集2
BingBingFan apple dew point photo gallery1
Embarrassing things comic collection1
Household design classic black and white
Li Zongrui hunting video screenshots1
Download software ranking
Tram sex maniac 2 (H) rar bag11
Boxer Classic video1
Tram sex maniac 2 (H) rar bag19
Eclipse 4.2.2 For Win32
Boxer vs Yellow4
Unix video tutorial8
Detective task-the top secret prostitution files
Boxer Classic video2
WebService在.NET中的实战应用教学视频 → 第3集
The king of fighters 97(Mobile phone games-apk)
归海一刀 published in(发表于) 2014/1/30 0:58:31 Edit(编辑)
ASP.NET2.0连接ORACLE解决方案_[Asp.Net教程]

ASP.NET2.0连接ORACLE解决方案_[Asp.Net教程]

ASP.NET2.0连接ORACLE解决方案_[Asp.Net教程]


以前写.net都用SQL Server2005数据库,但公司里要用Oracle 9i数据库,只能改程序的接口了,我从网上查了很多文章,很多都只说了一个方面,试验起来都不成功,测试了好多次终于成功了,所以做个简单得Demo把解决方法告诉遇到此类问题的朋友们。
Demo界面: Default.aspx


界面上添加的控件:
两个TextBox: tEmail(用于输入用户email),tPassword(用于输入注册密码
)
一个
Button: bReg
一个Label: lLable(用于注册成功后显示应答)

Demo的代码: Default.aspx.cs
我们先把数据的连接字符串写在Web.config:



下面是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["oracleconn"];,并且需先在填加引用的.NET组件框里选择System.Configuration添加后才能用。

好了,工作做完了,一切OK。






添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.