Solved

A macro substitution function

Posted on 2004-08-24
4
274 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

756 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