[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

A macro substitution function

Hello everyone there,

I am using VB.net and I want an equivalent of a macro substitution function and what I need is if I had info stored in a variable to use the data in the variable.  This is what I mean:

Dim Field1, Field2, Field3 As String

m_daDataAdapter = _
                New OleDb.OleDbDataAdapter("SELECT * FROM PAF _
ORDER BY Surname, ItemNumber, Dept", m_cnADONetConnection)

But instead of using the actual field names be able to use the values stored in Field1, Field2 and Field3.  Meaning that I can sort on different fields any time.

Anyone there with a solution?   Thanks in advance.

HenDee
0
HenDee
Asked:
HenDee
  • 2
1 Solution
 
RonaldBiemansCommented:
you mean like this

dim field1 as string = "Surname"
dim field2 as string = "Itemnumber"
dim field3 as string = "Dept"


m_daDataAdapter = _
                New OleDb.OleDbDataAdapter("SELECT * FROM PAF _
ORDER BY " & field1 & " , " & field2 & ","  & field3 , m_cnADONetConnection)

0
 
planoczCommented:
also here is an example that I use.....

sTableName =" PAF"  

     '*********** FOR ADO.NET **********************
        Dim sSQL As String = "SELECT * FROM  & sTableName  & " " & _
ORDER BY Surname, ItemNumber, Dept", m_cnADONetConnection)

        AccessConnection(sSQL)
 
0
 
planoczCommented:
also here is an example that I use.....

sTableName =" PAF"  

     '*********** FOR ADO.NET **********************
        Dim sSQL As String = "SELECT * FROM  & sTableName  & " " & _
                                         "ORDER BY Surname, ItemNumber, Dept"

        AccessConnection(sSQL)


'MOD CLASS

    Public DS As DataSet
    Public sDBPass As String = ""
    Public sUSERid As String = ""
    Public myDataAdapter As OleDb.OleDbDataAdapter
 
Public Sub AccessConnection(ByVal SQL As String)
        Try
            Dim strConnectionString As String
            strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
             "Data Source=Book.mdb;" & "User ID=" & sUSERid & ";" & _
             "Jet OLEDB:Database Password=" & sDBPass
            Dim Con As New System.Data.OleDb.OleDbConnection(strConnectionString)
            myDataAdapter = New System.Data.OleDb.OleDbDataAdapter(SQL, Con)
            Con.Open()
            ' Create and fill dataset
            DS = New DataSet(sTableName)
            myDataAdapter.Fill(DS, sTableName)
            Con.Close()
        Catch Ex As Exception
            MsgBox("Exception: " & Ex.Message & "  " & Ex.ToString, MsgBoxStyle.Critical)
        End Try
    End Sub
0
 
wguerramCommented:
There is not  macro substitution equivalent in .NET

Take a look at this

 New OleDb.OleDbDataAdapter(String.Format("SELECT * FROM PAF " & _
ORDER BY {0}, {1}, {2}", Field1, Field2, Field3), m_cnADONetConnection)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now