Solved

A macro substitution function

Posted on 2004-08-24
4
271 Views
Last Modified: 2010-08-05
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
Comment
Question by:HenDee
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 250 total points
ID: 11878658
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
 
LVL 27

Expert Comment

by:planocz
ID: 11880608
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
 
LVL 27

Expert Comment

by:planocz
ID: 11880638
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
 
LVL 8

Expert Comment

by:wguerram
ID: 11881839
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now