Can anyone give a good explantion of how this works(with examples) for simple connections, using SQL statements, etc. - or direct me to a good web site? I've been reading for awhile now and have only managed to get a headache. Recordsets in VB6 came so easy to me - everything was straight forward - set a connection, give a query, execute. The idea of a DataAdapter and a DataReader are foreign to me.
The most I have been able to do is the below code that reads information from a XLS file. However, if I try to enter the SQL statement to the DataAdapter anywhere other than during declaration I get an error. How do you program dynamically if you have to hard code a statement in and declare a new DataAdapter for a different statement? Also, what if I don't want to read, but delete, modify, etc.? The idea of filling a data set when I want to delete records seems bizare.
Anyway, any pointers are welcome. I just can't seem to find a good reference for ADO .NET 2.0 that covers all the basics.
Thanks,
-Tril
Dim xlsConnection As New System.Data.OleDb.OleDbConnection
Dim xlsDataAdapter As New System.Data.OleDb.OleDbDataAdapter("SELECT * FROM [JOBS$]", xlsConnection)
Dim xlsDataSet As DataSet = New DataSet
Dim xlsDataRow As DataRow
xlsConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\Brian\WIP\BrianWIPLIST.xls;Extended Properties=Excel 8.0;HDR=Yes;IMEX=1"
xlsDataAdapter.Fill(xlsDataSet)
For Each xlsDataRow In xlsDataSet.Tables(0).Rows
If xlsDataRow("JOB #").ToString = String.Empty Then
Else
If IsNumeric(xlsDataRow("JOB #") Then
msgbox(xlsDataRow("JOB #"))
End If
End If
Next
xlsConnection.Close()
Enter your message below
Sign in or Join us (it's free).