欢迎光临
我们一直在努力

c#与oracle的连接!-.NET教程,C#语言

建站超值云服务器,限时71元/月

using system.data.oledb;

新建一个类(用于数据库连接的参数):

public static string getoracledbconnstr()

{

// 数据库连接

string tempuser="system",temppassword="andystarmkmk",tempdatasource="andy";

string tempstrcon="provider=oraoledb.oracle.1;persist security info=false;"+

"user id="+tempuser+";password="+temppassword+";data source="+tempdatasource;

return tempstrcon;

}

设置click事件:

private void button1_click(object sender, system.eventargs e)

{

string strsql="select * from scott.aa";

string tempstrcon=form1.getoracledbconnstr();

string tempstrcom="select * from scott.aa";

oledbconnection tempmyconn=new oledbconnection(tempstrcon);

dataset tempmydataset=new dataset();

oledbdataadapter tempmycommand=new oledbdataadapter (tempstrcom,tempmyconn);

tempmycommand.fill(tempmydataset);

tempmyconn.open();

datagrid1.datasource =tempmydataset;

oledbcommand tempcommand=new oledbcommand(strsql,tempmyconn);

tempcommand.executenonquery();

tempmyconn.close();

}

注意:

1.连接数据库需要的参数:

◎oledbconnection 用于建立连接

◎dataset 数据在内存中的缓存,就是在内存中建立一个与数据库一致的表

◎oledbdataadapter 用于更新数据源

◎oledbcommand 用于执行sql命令

2.连接完成后应该马上关闭连接。

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » c#与oracle的连接!-.NET教程,C#语言
分享到: 更多 (0)

相关推荐

  • 暂无文章