I am trying to get my head around data access using VB.NET 2010.
I am slowly building a dummy application of contacts. I have it working with an SQL command object to handle the ADD, UPDATE and DELETE but it inly supports single table queries. I know I have to set the commands manually if there is a join but not sure how.
Here is my current code that retrieves the data from a Contact table and and a Contact Type Table
Private Sub frmContacts_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Try
bloading = True 'variable to denote form is loading
ModMain.InitaliseDBConnection() ' open connection to database using public connection "cn"
sqlAdapter = New SqlDataAdapter(sSqlContactsJoined, cn)
sqlAdapter.Fill(datblContacts) 'fill datatable with result of sSqlContactsJoined
CmdBuilder = New SqlCommandBuilder(sqlAdapter) 'generate the ADD, UPDATE and DELETE statements
dgrdContacts.DataSource = datblContacts
FormatGrid() 'Set the headers and hide ID columns on datagrid
FillComboBox() 'fill combobox with ContactTypes
bloading = False
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
The value of sSqlContactsJoined is :
Dim sSqlContactsJoined As String = "SELECT dbo.tblContacts.*, dbo.tblContactType.ContactType FROM " _
& " dbo.tblContacts INNER JOIN dbo.tblContactType ON dbo.tblContacts.ContactTypeID = dbo.tblContactType.ContactTypeID"
any pointers to a tutorial that may show me how to manually enter the ADD UPDATE & DELETE statements for the CommandBulder?