
基本思路是:
1.在.net中创建一个数据源对象,初学者可以直接用系统提供的sqldatasource对象;在创建数据源对象的时候,向导会引导你连接到你的sql服务器上,并指定要 *** 作的数据库和数据表,通过语句构造器选出你需要的数据,如果需要增删改,则需要同时选中insert、update、delete语句;
2.创建一个数据控件,来实现增删改查。最简单的就是拖动一个gridview控件,然后设置数据绑定,把该gridview控件的数据源设为第一步中的sqldatasource对象。同时选中该gridview控件的插入、删除、修改选项
3.如需要干预增删改查,在相应的inserting\updating\deleting\selecting事件中编写代码,以更改默认的动作。在上述事件处理程序中,通过控制commandparameter来实现干预。
如果不用ORM框架,那么直接引入ojdbc6.jar 驱动包,然后在代码中JDBC配置
然后可以使用jdbc实现增删改查,比如下面代码
ResultSet rs = nullStatement stmt = null
Connection conn = null
try {
Class.forName("oracle.jdbc.driver.oracleDriver")
//new oracle.jdbc.driver.oracleDriver()
conn = DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.1:1521:yuewei", "scott", "tiger")
stmt = conn.createStatement()
rs = stmt.executeQuery("select * from dept")
while(rs.next()) {
System.out.println(rs.getString("deptno"))
//System.out.println(rs.getInt("deptno"))
}
} catch (ClassNotFoundException e) {
e.printStackTrace()
} catch (SQLException e) {
e.printStackTrace()
} finally {
try {
if(rs != null) {
rs.close()
rs = null
}
if(stmt != null) {
stmt.close()
stmt = null
}
if(conn != null) {
conn.close()
conn = null
}
} catch (SQLException e) {
e.printStackTrace()
}
}
2.
增insert into table (id, name)values(1, '张三')删delete from table where name = '张三'
改update table set name = '李四' where id = 1
查select id, name from table
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)