Solved

A macro substitution function

Posted on 2004-08-24
4
275 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

739 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