Use 2 different databases

S

shapper

Hello,

I have created a function which creates a DataTable from a Database.

However, I want to be able to use an Access or aSQL database.

Do I need to create 2 complete different functions?

The method is the same, only the types change.

Here is my code:

' Define connection
Dim connection As New
SqlClient.SqlConnection(connectionString.ToString)

' Define command
Dim command As New SqlClient.SqlCommand
With command
.CommandText = "GetRecords"
.Connection = connection
.CommandType = CommandType.StoredProcedure
End With

' Add command parameters
With command.Parameters
.Add(New SqlClient.SqlParameter("@Value", Value))
End With

connection.Open()
...
Create DataTable
...
connection.Close()

Thanks,

Miguel
 
J

Jeff Dillon

Yes, but not with SQLClient (sql server only)

Consider using the OLEDB methods

Jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top