locked
How to call scalar value function from vb.net RRS feed

  • Question

  • User-184135847 posted

    I have one scalar value function defined in sql database.

    It accespts 2 parameters and return an integer.

    Can anyone please help how to call UDF from vb.net using oledeb?

    Thanks in advance.

    Wednesday, April 20, 2011 11:23 AM

Answers

  • User1508394307 posted

    Dim sampleCMD As OleDbCommand = New OleDbCommand("SampleProc", nwindConn)
    sampleCMD.CommandType = CommandType.StoredProcedure
    
    Dim sampParm As OleDbParameter = sampleCMD.Parameters.Add("RETURN_VALUE", OleDbType.Integer)
    sampParm.Direction = ParameterDirection.ReturnValue
    
    sampParm = sampleCMD.Parameters.Add("@InputParm", OleDbType.VarChar, 12)
    sampParm.Value = "Sample Value"
    
    sampParm = sampleCMD.Parameters.Add("@OutputParm", OleDbType.VarChar, 28)
    sampParm.Direction = ParameterDirection.Output
    
    nwindConn.Open()
    
    Dim sampReader As OleDbDataReader = sampleCMD.ExecuteReader()
    
    Console.WriteLine("{0}, {1}", sampReader.GetName(0), sampReader.GetName(1))
    
    Do While sampReader.Read()
      Console.WriteLine("{0}, {1}", sampReader.GetInt32(0), sampReader.GetString(1))
    Loop
    
    sampReader.Close()
    nwindConn.Close()
    
    Console.WriteLine(" @OutputParm: {0}", sampleCMD.Parameters("@OutputParm").Value)
    Console.WriteLine("RETURN_VALUE: {0}", sampleCMD.Parameters("RETURN_VALUE").Value)
    http://msdn.microsoft.com/en-us/library/yy6y35y8.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 21, 2011 1:36 PM