not all code paths return a value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hailua
    New Member
    • Jan 2008
    • 4

    not all code paths return a value

    [code=vbnet]
    using System;
    using System.Data;
    using System.Data.Sql Client;
    using System.Data.Sql Types;
    using Microsoft.SqlSe rver.Server;
    using System.Collecti ons;

    public partial class UserDefinedFunc tions
    {
    [Microsoft.SqlSe rver.Server.Sql Function(FillRo wMethodName="Ob j_Row",
    IsDeterministic =true,
    IsPrecise=true,
    TableDefinition ="ObjID int,OjbDataID int,ObjDataValu e nvarchar(400)",
    DataAccess= DataAccessKind. Read)]

    public static IEnumerable Obj_IDs(SqlInt3 2 Data_1, SqlInt32 Data_2, SqlInt32 Data_3)
    {
    using (SqlConnection conn = new SqlConnection(" context connection=true "))
    {
    try
    {
    if (!Data_2.IsNull )
    {
    string sql = @"Select Obj_ID, Obj_Data_ID, Obj_Data_Value from tbl_Obj_2";
    SqlCommand cmd = new SqlCommand(sql, conn);
    SqlDataAdapter da = new SqlDataAdapter( cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);
    conn.Open();
    return dt.Rows;
    }
    // if (!Data_3.IsNull )
    //{
    // string sql = @"Select Obj_ID, Obj_Data_ID, Obj_Data_Value from tbl_Obj_3";
    // SqlCommand cmd = new SqlCommand(sql, conn);
    // SqlDataAdapter da = new SqlDataAdapter( cmd);
    // DataTable dt = new DataTable();
    // da.Fill(dt);
    // conn.Open();
    // return dt.Rows;
    //}
    }
    catch (Exception ex)
    {
    ex.Message.ToSt ring();
    }
    finally
    {
    conn.Close();
    }

    }

    }
    public static void Obj_Row(Object item, out int ObjID, out int ObjDataID, out string ObjDataValue)
    {
    DataRow row = (DataRow)item;
    ObjID = Convert.ToInt32 (row["Obj_ID"]);
    ObjDataID = Convert.ToInt32 (row["Obj_Data_I D"]);
    ObjDataValue = row["Obj_Data_Value "].ToString();
    }

    };[/code]

    Error 1 'UserDefinedFun ctions.Obj_IDs( System.Data.Sql Types.SqlInt32, System.Data.Sql Types.SqlInt32, System.Data.Sql Types.SqlInt32) ': not all code paths return a value

    I'm newbie. Please, show me how to correct the problem. I did look some discussion in here say I have to return some thing in catch or finally. I'm some kind of stupid. so I'm still not understand why? and how?. Thank you.
    Last edited by debasisdas; Jan 7 '08, 12:32 PM. Reason: Formatted using code=vbnet tags
  • hailua
    New Member
    • Jan 2008
    • 4

    #2
    code use C# tag. I solve the problem with ==>Else. Thanks for reading my post.

    Comment

    Working...