I have been looking around the internet for a while and still can not find what I am looking for. So I am posting to see if I can get any help.
I have a SQL 2005 DB with a table named Customers. I have a application that needs to connect to this DB. I need the app to have buisness logic in it. The issue is that the app will be installed onto different enviorments each with a different server name and DB name. What would be the easiest way to implement this. I created Customer class and added public properties with the name of the fields. I then used binding source and navigator. The code works fine but when I add code to the property fields nothign happens. I would like to add code for validation. Also the property names must be the same name as the fields. Can anyone help. The class file looks like this.
Imports System.Data.SqlClient
Namespace Customers
Public Class Customers
Private CustomerGuid As Guid
Private strCompany As String
Private ContactLName As String
Private dsCustomers As New DataSet
Private daCustomers As SqlDataAdapter
Public Sub New()
daCustomers = New SqlDataAdapter("SELECT * FROM Customers", My.Settings.DBConn)
Dim sqlcmdbuilder As New SqlCommandBuilder(daCustomers)
daCustomers.Fill(dsCustomers, "Customers")
'Call GetCustomers()
'ContactFirstName = Me.dsCustomers.Tables("Customers").Columns("ContactFirstName")
'Me.ContactLastName = CStr(Me.dsCustomers.Tables("customers").Rows.Item(0).Item("ContactLastName"))
End Sub
Public Property ContactLastName() As String
Get
Return ContactLName
MessageBox.Show(ContactLastName, "Get")
End Get
Set(ByVal value As String)
ContactLName = value
MessageBox.Show(ContactLName, "Set")
End Set
End Property
Public ReadOnly Property CustomerID() As Guid
Get
Return CustomerGuid
End Get
End Property
Public Property CompanyName() As String
Get
Return strCompany
End Get
Set(ByVal value As String)
strCompany = value
End Set
End Property
Public Property CustomerDS() As DataSet
Get
Return dsCustomers
End Get
Set(ByVal value As DataSet)
dsCustomers = value
End Set
End Property
Public Function GetCustomers() As DataSet
Return dsCustomers
End Function
Public Function SaveCustomers() As Boolean
daCustomers.Update(dsCustomers, "Customers")
Return True
End Function
End Class
End Namespace
Here is the code on the form:
Dim customer As New Customers.Customers
Form Load:
Me.CustomersBindingSource.DataSource = customer.GetCustomers
I have a SQL 2005 DB with a table named Customers. I have a application that needs to connect to this DB. I need the app to have buisness logic in it. The issue is that the app will be installed onto different enviorments each with a different server name and DB name. What would be the easiest way to implement this. I created Customer class and added public properties with the name of the fields. I then used binding source and navigator. The code works fine but when I add code to the property fields nothign happens. I would like to add code for validation. Also the property names must be the same name as the fields. Can anyone help. The class file looks like this.
Imports System.Data.SqlClient
Namespace Customers
Public Class Customers
Private CustomerGuid As Guid
Private strCompany As String
Private ContactLName As String
Private dsCustomers As New DataSet
Private daCustomers As SqlDataAdapter
Public Sub New()
daCustomers = New SqlDataAdapter("SELECT * FROM Customers", My.Settings.DBConn)
Dim sqlcmdbuilder As New SqlCommandBuilder(daCustomers)
daCustomers.Fill(dsCustomers, "Customers")
'Call GetCustomers()
'ContactFirstName = Me.dsCustomers.Tables("Customers").Columns("ContactFirstName")
'Me.ContactLastName = CStr(Me.dsCustomers.Tables("customers").Rows.Item(0).Item("ContactLastName"))
End Sub
Public Property ContactLastName() As String
Get
Return ContactLName
MessageBox.Show(ContactLastName, "Get")
End Get
Set(ByVal value As String)
ContactLName = value
MessageBox.Show(ContactLName, "Set")
End Set
End Property
Public ReadOnly Property CustomerID() As Guid
Get
Return CustomerGuid
End Get
End Property
Public Property CompanyName() As String
Get
Return strCompany
End Get
Set(ByVal value As String)
strCompany = value
End Set
End Property
Public Property CustomerDS() As DataSet
Get
Return dsCustomers
End Get
Set(ByVal value As DataSet)
dsCustomers = value
End Set
End Property
Public Function GetCustomers() As DataSet
Return dsCustomers
End Function
Public Function SaveCustomers() As Boolean
daCustomers.Update(dsCustomers, "Customers")
Return True
End Function
End Class
End Namespace
Here is the code on the form:
Dim customer As New Customers.Customers
Form Load:
Me.CustomersBindingSource.DataSource = customer.GetCustomers