Access SQL functions through .net??

Last post 10-19-2006 2:54 PM by dilbert1947. 3 replies.

Sort Posts:

  • Access SQL functions through .net??

    10-18-2006, 3:56 PM
    • Member
      262 point Member
    • dilbert1947
    • Member since 08-26-2006, 6:00 PM
    • Posts 171
    I usually access stored procedures using SQL data source. But now  I need a string returned from the database. If I write a function in SQL how do I access it from an aspx.vb file?
  • Re: Access SQL functions through .net??

    10-18-2006, 5:45 PM
    • All-Star
      77,920 point All-Star
    • jeff@zina.com
    • Member since 09-26-2003, 10:43 AM
    • Naples, FL, USA
    • Posts 10,599
    • Moderator
      TrustedFriends-MVPs

    Put it in a proc and run an EXEC query, same way as any other procedure.

    Jeff

    Blatant Self Promotion: ASP.NET 3.5 CMS Development
  • Re: Access SQL functions through .net??

    10-18-2006, 11:06 PM
    Answer
    • Star
      12,930 point Star
    • Iori_Jay
    • Member since 04-04-2006, 10:21 AM
    • Posts 2,450

    If the SQL function returns a string, why not use SqlCommand.ExecuteScalar method:

     using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["myConn"].ToString()))
                {
                    conn.Open();
                   
                    string qstring = "SELECT dbo.fn_test('IORI')";

                    SqlCommand cmd = new SqlCommand(qstring, conn);
                    string s=cmd.ExecuteScalar().ToString();
                       
                    Response.Write("The new string is:" + s);
                }

    Welcome to my SQL/ASPNET forum for Chinese
    http://51up.org/bbs/forumdisplay.php?fid=38
  • Re: Access SQL functions through .net??

    10-19-2006, 2:54 PM
    • Member
      262 point Member
    • dilbert1947
    • Member since 08-26-2006, 6:00 PM
    • Posts 171
    Cool! Thanks guys!
Page 1 of 1 (4 items)