It depends on what you mean by better. There are advantages to using the System.Data.SqlClient.SqlConnection, but you're connection string will be stored in plaintext in your code.
But if you would like to reference an existing Grooper Data Connection here is an example of my colleague's script.
‘This makes the property appear in the UI.
<DataMember> Public DataConnectionId As Guid = Guid.Empty
''' <summary>Specify the database
table that will store the audit results.</summary>
Category("Connections"), Viewable, UI(GetType(NodeReferenceEditor)),
Public Property DatabaseTable As DatabaseTable
If (DataConnectionId =
Guid.Empty) Then Return Nothing
Set(value As DatabaseTable)
If (value Is Nothing) Then
DataConnectionId = Guid.Empty
DataConnectionId = value.Id
‘This custom function executes the query,
saves to a Data.DataTable, and closes the SQL connection. I pass everything to
a function like this as much as possible to keep the sql connection closed
efficiently. The command parameter is statement you’d write in SQL.(Select,
Update, Insert Into, Delete, Etc.)
Private Function Query(command As String) As Data.DataTable
Dim db As Database =
Dim dt =
db.Disconnect() : db = Nothing