Visual Basic.NET快速开发MIS系统

哎呦喂嘿哼

哎呦喂嘿哼

2016-01-29 12:09

Visual Basic.NET快速开发MIS系统,Visual Basic.NET快速开发MIS系统
  引言

  以前版本的Visual Basic虽然号称自己是一种OOP(面向对象)编程语言,但却不是一个地地道道的OOP编程语言,最多只是半个面向对象的编程语言。但Visual Basic.NET已经是一种完全的面向对象的编程语言。他支持面向对象的所有基本特征:继承、多态和重载。这使得以前在Visual Basic中很难或根本实现不了的问题,在Visual Basic.NET中可以顺利的用简单的方法实现。

  自定义数据操作类

  定义一个数据访问的基类,并编写有关数据库操作的必要方法。

  定义一个数据访问类,类名为CData。定义连接Oracle数据库的方法ConnOracle,获取数据集的方法GetDataSet, 获取物理表的方法GetDataTable, 向物理表中插入一行数据的方法Insert, 向物理表中删除数据的方法Delete, 向物理表中更新数据的方法Update。其实现方法不是本文的重点,在此仅给出代码,不作详细分析。代码如下:

Public Class CDataBase
Dim OleCnnDB As New OleDbConnection()

连接Oracle数据库,ServerName:服务器名,UserId:用户名,UserPwd:用户密码
Public Function ConnOracle(ByVal ServerName As String, ByVal UserId As String, ByVal UserPwd As String) As OleDbConnection

 Dim OleCnnDB As New OleDbConnection()
 With OleCnnDB
  .ConnectionString = "Provider=MSDAORA.1;Password=" & UserPwd & ";User ID=" & UserId & ";Data Source=" & ServerName & ""
  Try
   .Open()
  Catch er As Exception
   MsgBox(er.ToString)
  End Try
 End With
 mOleCnnDB = OleCnnDB
 Return OleCnnDB
End Function

获取数据集。TableName:表名,strWhere:条件
Public Overloads Function GetDataSet(ByVal TableName As String, ByVal strWhere As String) As DataSet

 Dim strSql As String
 Dim myDataSet As New DataSet()
 Dim myOleDataAdapter As New OleDbDataAdapter()

 myOleDataAdapter.TableMappings.Add(TableName, TableName)
 strSql = "SELECT * FROM " & TableName & " where " & strWhere

 myOleDataAdapter.SelectCommand = New OleDbCommand(strSql, mOleCnnDB)
 Try
  myOleDataAdapter.Fill(myDataSet)
 Catch er As Exception
  MsgBox(er.ToString)
 End Try
 Return myDataSet
End Function

获取物理表。TableName:表名
Public Overloads Function GetDataTable(ByVal TableName As String) As DataTable
 Dim myDataSet As New DataSet()
 myDataSet = GetDataSet(TableName)
 Return myDataSet.Tables(0)
End Function

获取物理表。TableName:表名,strWhere:条件
Public Overloads Function GetDataTable(ByVal TableName As String, ByVal strWhere As String) As DataTable

 Dim myDataSet As New DataSet()
 myDataSet = GetDataSet(TableName, strWhere)
 Return myDataSet.Tables(0)
End Function

 向物理表中插入一行数据。TableName:表名,Value:行数据,BeginColumnIndex:开始列
Public Overloads Function Insert(ByVal TableName As String, ByVal Value As Object, Optional ByVal BeginColumnIndex As Int16 = 0) As Boolean

 Dim myDataAdapter As New OleDbDataAdapter()
 Dim strSql As String
 Dim myDataSet As New DataSet()
 Dim dRow As DataRow
 Dim i, len As Int16

 strSql = "SELECT * FROM " & TableName
 myDataAdapter.SelectCommand = New OleDbCommand(strSql, mOleCnnDB)
 Dim custCB As OleDbCommandBuilder = New OleDbCommandBuilder(myDataAdapter)
 myDataSet.Tables.Add(TableName)
 myDataAdapter.Fill(myDataSet, TableName)
 dRow = myDataSet.Tables(TableName).NewRow
 len = Value.Length
 For i = BeginColumnIndex To len - 1
  If Not (IsDBNull(Value(i)) Or IsNothing(Value(i))) Then
   dRow.Item(i) = Value(i)
  End If
 Next
 myDataSet.Tables(TableName).Rows.Add(dRow)
 Try
  myDataAdapter.Update(myDataSet, TableName)
 Catch er As Exception
  MsgBox(er.ToString)
  Return False
 End Try
展开更多 50%)
分享

猜你喜欢

Visual Basic.NET快速开发MIS系统

vb
Visual Basic.NET快速开发MIS系统

从 Visual Basic 6.0 到 Visual Basic.NET 的转换(4)

vb
从 Visual Basic 6.0 到 Visual Basic.NET 的转换(4)

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

从 Visual Basic 6.0 到 Visual Basic.NET 的转换(5)

vb
从 Visual Basic 6.0 到 Visual Basic.NET 的转换(5)

Visual Basic.NET编程的设计思考

vb
Visual Basic.NET编程的设计思考

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

从 Visual Basic 6.0 到 Visual Basic.NET 的转换(1)

vb
从 Visual Basic 6.0 到 Visual Basic.NET 的转换(1)

从 Visual Basic 6.0 到 Visual Basic.NET 的转换(2)

vb
从 Visual Basic 6.0 到 Visual Basic.NET 的转换(2)

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

《天天酷跑》有炫飞模式任务解析

《天天酷跑》有炫飞模式任务解析

VB.NET注册表编程

VB.NET注册表编程
下拉加载更多内容 ↓