。net不用控件的增删查改(与oracle数据库)

求大神帮忙,最好有源代码

.net中用jdbc实现增删改查:

以users表为例,有三个字段,自增长的编号id,int类型;名称name,nvarchar类型,密码pwd,nvarchar类型
首先在vs2005中引入System.Data.OracleClient;命名空间

1、添加数据到users:
publicint Insert(stringname, string pwd)
{
OracleConnectionconn = new OracleConnection(@"Data Source=SBZX;User ID=simis;Password=zeda");
conn.Open();
stringsql = "insert into users(name,pwd)values(:name,:pwd)";
OracleCommandcmd = new OracleCommand(sql,conn);
OracleParameter parn = new OracleParameter(":name", name);
cmd.Parameters.Add(parn);
OracleParameter parp = new OracleParameter(":pwd", name);
cmd.Parameters.Add(parp);
int result = cmd.ExecuteNonQuery(); //result接收受影响行数,也就是说result大于0的话表示添加成功
conn.Close();
cmd.Dispose();
return result;
}
2、删除users数据表
publicint delete(int id)
{
OracleConnectionconn = new OracleConnection(@"Data Source=SBZX;User ID=simis;Password=zeda");
conn.Open();
stringsql = "delete from users where id=:id";
OracleCommandcmd = new OracleCommand(sql,conn);
OracleParameterpari = new OracleParameter(":id", id);
cmd.Parameters.Add(pari);
int result = cmd.ExecuteNonQuery(); //result接收受影响行数,也就是说result大于0的话表示添加成功
conn.Close();
cmd.Dispose();
return result;
}
3、更新users数据表
public int update(stringname, string pwd, intid)
{
OracleConnectionconn = new OracleConnection(@"Data Source=SBZX;User ID=simis;Password=zeda");
conn.Open();
stringsql = "update users set name=:name,pwd=:pwdwhere id=:id";
OracleCommandcmd = new OracleCommand(sql,conn);
OracleParameterparn = new OracleParameter(":name", name);
cmd.Parameters.Add(parn);
OracleParameterparp = new OracleParameter(":pwd", name);
cmd.Parameters.Add(parp);
OracleParameterpari = new OracleParameter(":id", id);
cmd.Parameters.Add(pari);
intresult = cmd.ExecuteNonQuery();
conn.Close();
cmd.Dispose();
returnresult;
}
4、查询数据表,整表查询
publicDataTable Select()
{
OracleConnectionconn = new OracleConnection(@"Data Source=SBZX;User ID=simis;Password=zeda");
conn.Open();
stringsql = "select * from users";
OracleCommandcmd = new OracleCommand(sql,conn);
OracleDataAdapteroda = new OracleDataAdapter(cmd);
DataTable dt = new DataTable();
oda.Fill(dt);
conn.Close();
cmd.Dispose();
return dt;
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-07-02
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

//首先要引进两个命名空间 System.Data.sqlClient 以及System.Data 这里有着操作数据库的类

namespace ado
{
class Program
{
static void Main(string[] args)
{本回答被提问者采纳
相似回答