今天没有抄代码,按自己的理解码了个程序,耗时一天。可喜的是,在三层架构这方面成功了。感觉三层之间的关系是调用,实体类(model)就是一个类。UI调用BLL,BLL调用DAL这样。虽然最后成功了,但是过程中还是出现了让我头疼的问题,仍不知原因。
今天这个项目连接Access数据库出现了“未在本地计算机上注册Microsoft.Jet.Oledb.4.0”的错误,经百度
最终暂时解决该错误的办法时在项目中配置属性管理器里将AnyCPU改为x86。但是昨天我试验网上摘抄的代码时,同样的语句,同样的引用,却并未出现该问题。今天仍旧可以正常运行。今天出现这个问题肯定是哪里漏掉什么了,求大神帮我解惑。
贴上我今天三层架构的代码,请大佬们给我指点指点哪里有不合适或者不规范的地方,望不吝赐教。
(今天主要想试验三层架构的结构和相互的关系,所以每层并没有写太复杂的东西,BLL层也没加入逻辑判断,U层也没有添加控件)
Model:
Public Class Task
Public _datetime As DateTime
Public _task As String
Public _from As String
Public _initiator As String
Public _recipient As String
Public _reminder As DateTime
'Public _interval As Integer
Public Property DateTime() As DateTime
Get
Return _datetime
End Get
Set(value As DateTime)
_datetime = value
End Set
End Property
Public ReadOnly Property myDate() As DateTime
Get
Return _datetime.Date
End Get
End Property
Public Property Task() As String
Get
Return _task
End Get
Set(value As String)
_task = value
End Set
End Property
Public Property From() As String
Get
Return _from
End Get
Set(value As String)
_from = value
End Set
End Property
Public Property Initiator() As String
Get
Return _initiator
End Get
Set(value As String)
_initiator = value
End Set
End Property
Public Property Recipient() As String
Get
Return _recipient
End Get
Set(value As String)
_recipient = value
End Set
End Property
'Public Property Interval() As Integer
' Get
' Return _interval
' End Get
' Set(value As Integer)
' _interval = value
' End Set
'End Property
Public ReadOnly Property Reminder() As DateTime
Get
Return _datetime.AddMinutes(-15)
End Get
End Property
End Class
UI:
Private Sub Floating_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim dptask As New BLL.taskManager
DataGridView1.DataSource = dptask.DisplayData
End Sub
BLL:
Public Class taskManager
Public Function DisplayData() As DataView
Dim objTaskDAO As New DAL.taskDAO
Return objTaskDAO.GetData
End Function
End Class
DAL:
Imports System.Data
Imports System.Data.OleDb
Public Class taskDAO
Public Function GetData() As DataView
Dim strCn As String = "provider=microsoft.ace.oledb.12.0;data source=|datadirectory|\workassist.mdb"
Dim cnn As New OleDbConnection(strCn)
Dim cmd As OleDbCommand
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
Dim dv As New DataView
Dim strSql As String = "select * from tasks"
cmd = New OleDbCommand(strSql, cnn)
cmd.CommandText = strSql
cmd.CommandType = CommandType.Text
da.SelectCommand = cmd
cnn.Open()
da.Fill(ds, "tasks")
dv = ds.Tables("tasks").DefaultView
cnn.Close()
Return dv
End Function
End Class