Solved

A macro substitution function

Posted on 2004-08-24
4
269 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

19 Experts available now in Live!

Get 1:1 Help Now