.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;
}
温馨提示:答案为网友推荐,仅供参考