Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling udf from sqlhelper

Status
Not open for further replies.

chris123321

IS-IT--Management
Joined
Mar 13, 2007
Messages
139
Location
US
Can I use the SqlHelper to call a udf?

Or is there another way to call an udf in sql Server?

From doing a little research I found out that udfs are only part of SQL Server and VB.NET cannot call udfs. Just wanted to validate that.

Thanks.
 
you can call the udf through a command. If the udf does not return a value just use a ExecuteNonQuery. If it doesn't look into ExecuteScalar method

____________ signature below ______________
The worst mistake you'll ever make is to do something simply the way you know how while ignoring the way it should be done
 
Is this a good example:

Code:
SqlConnection conn = new SqlConnection("context connection=true");
conn.Open();
SqlCommand cmd = conn.CreateCommand();

// 1. this is a user-defined function
// returning a single value (authorname) as VARCHAR
cmd.CommandText = "GetFullAuthorNameById";
// required from procedure or UDF
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", "172-32-1176");


Thanks.
 
Code:
SqlConnection conn = new SqlConnection("context connection=true");
conn.Open();
SqlCommand cmd = conn.CreateCommand();

// 1. this is a user-defined function
// returning a single value (authorname) as VARCHAR
cmd.CommandText = "GetFullAuthorNameById";
// required from procedure or UDF
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@id", "172-32-1176");

String fullname = (String)cmd.ExecuteScalar();
// use fullname
cmd.Parameters.Clear();
 
You know this is not the C# forum right?

____________ signature below ______________
The worst mistake you'll ever make is to do something simply the way you know how while ignoring the way it should be done
 
Yes, but the example I found was in C#..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top