1

i am new to postgresql, and now we have to change our code in C# for using db as postgresql from sql, following code is working fine with sql

        public PL.Type GetDetails(int ID)
        {
            PL.Type obj = null;

            SqlParameter[] parameters = new SqlParameter[]
            {
              new SqlParameter("@Action", "GetDetails"),
              new SqlParameter("@ID", ID)
            };
            //Lets get the list of all Type in a datataable
            using (DataTable table = DL.SqlDbHelper.ExecuteParamerizedSelectCommand("sp_Type", CommandType.StoredProcedure, parameters))
            {
                //check if any record exist or not
                if (table.Rows.Count == 1)
                {
                    DataRow row = table.Rows[0];

                    //Lets go ahead and create the list of Type
                    obj = new PL.Type();

                    //Now lets populate the Type details into the list of Types
                    obj.ID = Convert.ToInt32(row["ID"]);
                    obj.Name = row["Name"].ToString();
                }
            }

            return obj;
        }

but when we are trying the same to use postgresql db its not working, changed code for postgresql is as under

        public PL.Type GetDetails(int ID)
        {
        PL.Type obj = null;

        NpgsqlParameter[] parameters = new NpgsqlParameter[]
        {
            new NpgsqlParameter("@Action", "GetDetails"),
            new NpgsqlParameter("@ID", ID)
        };
        //Lets get the list of all Type in a datataable
        using (DataTable table = DL.PostgreSQLDbHelper.ExecuteParamerizedSelectCommand("sp_Type", CommandType.StoredProcedure, parameters))
        {
            //check if any record exist or not
            if (table.Rows.Count == 1)
            {
                DataRow row = table.Rows[0];

                //Lets go ahead and create the list of Type
                obj = new PL.Type();

                //Now lets populate the Type details into the list of Types
                obj.ID = Convert.ToInt32(row["ID"]);
                obj.Name = row["Name"].ToString();
            }
        }

        return obj;
    }
S I
  • 80
  • 12
  • Why for the same (I suppose) stored procedure you pass only one parameter in the second example? – Steve Apr 30 '17 at 10:21
  • by mistake wrong part was updated, now rectify, please let me know how to rectify the same – S I May 01 '17 at 11:42
  • Can you explain what do you mean with _not working_? Did you get an error message? If yes what does it say? If not did you try to debug the code to check if you are getting correct results (ie Rows.Count==1)? – Steve May 01 '17 at 12:12
  • Could not load file or assembly 'System.Threading.Tasks.Extensions, Version=4.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The system cannot find the file specified. – S I May 01 '17 at 13:25
  • This has nothing to do with postgresql. Please read this question http://stackoverflow.com/questions/21057052/asp-net-app-crashes-could-not-load-file-or-assembly-microsoft-threading-tasks – Steve May 01 '17 at 13:32
  • ok, its working now, i just uninstalled and re install npgsql – S I May 01 '17 at 15:01

0 Answers0