title: How to call ms-access function from C#?
body: <p>I have written an ms-access function in a module called ‘StripLead’. I made a single line procedure called ‘CallFunction’. Now when I call this procedure from ms-access it works fine. But when I call this procedure from C# I get error:</p>
  
  <blockquote>
    <p>Undefined function 'Striplead' in expression.</p>
  </blockquote>
  
  <p>Ms-access module code:</p>
  
  <pre><code>Public Function StripLead(pstrPhrase As String) As String
    Dim strFirstWord As String
    Dim strReturn As String
    Dim intPos As Integer
  
    strReturn = pstrPhrase
    intPos = InStr(pstrPhrase, " ")
    If intPos &gt; 0 Then
      strFirstWord = Left$(pstrPhrase, intPos - 1)
      Select Case strFirstWord
        Case "A", "An", "The"
        strReturn = Right$(pstrPhrase, Len(pstrPhrase) - intPos)
      End Select
    End If
  
  StripLead = strReturn
  End Function
  </code></pre>
  
  <p>Ms-access procedure "CallFunction"(sql view):</p>
  
  <pre><code>SELECT Customers.ID, Striplead([ContactName]) AS a FROM Customers;
  </code></pre>
  
  <p>C# code: </p>
  
  <pre><code>   public void CallStoredProcedure(string NewQry)
         {
             try
             {
              DataTable tbl = new DataTable();
              using (OleDbConnection connection = new OleDbConnection(ConnectionString))
              {
                  OleDbCommand cmd = new OleDbCommand();
                  cmd.CommandText = "CallFunction";
                  cmd.CommandType = CommandType.StoredProcedure;
                  cmd.Connection = connection;
  
                  using (OleDbDataAdapter adp = new OleDbDataAdapter(cmd))
                  {
                      adp.Fill(tbl);
                  }
              }
  
           }
          catch(Exception ex)
          {
              throw;   
          }
      }
  </code></pre>
  
  <p>Please suggest whether the approach is incorrect. Or else, if there is a way to make call to ms-access function from C# to fetch data.
  My aim is to fetch modified data from ms-access and fill the datagrid in C#.</p>