SO community
I am getting started with ADO.NET and am fairly new to programming. I have had some support already from this community which has been very useful and had another question.
In simple terms, I am creating a simple windows form with a combobox of employee names and a button so that when the user clicks the button the selected employee's email address appears in a textbox on the form.
In my project I have database and on loading the form I connect to my database and create a datatable as shown below:
Public Class GetEmployeeDataset
Private tbl As New DataTable
Public Sub New()
Dim strConn, strSQL As String
strConn = "Data Source=.\SQLExpress;Initial Catalog=MyDatabase;Integrated Security=True;"
strSQL = "SELECT * FROM EmployeeTable"
Dim da As New SqlDataAdapter(strSQL, strConn)
da.Fill(tbl)
End Sub
End Class
At this point I have two questions:
- I am using DataTable as opposed to a DataSet because, as I understand it, a DataSet is a collection of DataTables and I only have one simple DataTable here (5 columns, 100 rows) so it seems easier just to use a DataTable. Anything wrong with that?
- Now that I have a DataTable ('tbl' in my example) how can I query that DataTable to retrieve the correct data i.e. EmailAddress based on employee name? In SQL it would be "SELECT EmailAddress WHERE EmployeeName = SelectedItem". I have looked at using the Select method of the DataTable but to no avail and then I went down the RowFilter method of DataView but without any success.
Can anybody point me in the right direction please?
Alex