简体   繁体   中英

I dont get any data from database

I have tried to pull data from database but i couldnt get the data in the loop,The X and Y returns "" value even after the dr gets the correct value(I am planning to plot x an y values in map):

    private void Map_it_Click( object sender, EventArgs e)
    {

            string Code = "";
            string strReturn = "";
            string X = "";
            string Y = "";

            var opt = "";
            List<CompanyDeat> listerrg = new List<CompanyDeat>();
            try
            {

                int name = 1;


                string ConStr = "";

                DataSet ds = new DataSet();

                ConStr = "Server=127.0.0.1; Port=5433; User Id=xxxx; Password=xxxxx; Database=xxxxx";

                using (NpgsqlConnection con = new NpgsqlConnection(ConStr))
                {

                    using (NpgsqlCommand cmd = new NpgsqlCommand("complete", con))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        NpgsqlDataAdapter da = new NpgsqlDataAdapter();

                        da.SelectCommand = cmd;
                        da.Fill(ds);
                    }
                }


                string errmsg = "";

                if (errmsg != "")
                {
                    Code = "0"; strReturn = errmsg;
                }
                else
                {
                    if (ds.Tables.Count > 0)
                    {
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            Code = "1";

                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            listerrg.Add(new CompanyDeat

                            {

                                X = dr["X"].ToString(),

                                Y = dr["Y"].ToString(),


                            });
                            map.DragButton = MouseButtons.Left;
                            map.MapProvider = GMapProviders.GoogleMap;
                            double lat = Convert.ToDouble(X);
                            double lon = Convert.ToDouble(Y);
                            map.Position = new PointLatLng(lat, lon);
                            map.MinZoom = 5;
                            map.MaxZoom = 100;
                            map.Zoom = 10;
                        }



                            if (strReturn == "1")
                            {
                                Console.Write("Updated");
                            }

                        }
                        //TripDT = TripDT.ToShortDateString();
                    }
                }
            }
            catch (Exception ex)
            {

            }
            return;




    }

But the data reaches dr but the value of X and Y becomes "" even after datas are assigned tp X an Y:

 ItemArray = {object[2]}
    18.0579309901531
    55.1186577950593

internal class:

internal class CompanyDeat
    {
        public string X { get; set; }
        public string Y { get; set; }

    }

postgresql code:

CREATE OR REPLACE FUNCTION complete() 
    RETURNS TABLE( X varchar,Y varchar) as
$BODY$   
    select "X","Y" from public.point ;

$BODY$
      LANGUAGE sql;

Kindly help,I need to complete it very soon

Assuming you got data in ds.Table[0]

List<CompanyDeat> target = ds.Table[0].AsEnumerable()
    .Select(row => new CompanyDeat
    {
        X= row.Field<string>(0),
        Y = row.Field<string>(1),
    }).ToList();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM