Reg:数据库中的现有数据 [英] Reg: Existing Data in database

查看:131
本文介绍了Reg:数据库中的现有数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在使用Attc设备(自动流量统计和分类设备) - 即Phoenix设备。在这里我想收集数据并存储在数据库中(这样我从设备收集数据并存储在数据库中)



我需要任何人的帮助我想检查数据库中的现有数据,如果它已经存在我不想在数据库中存储相同的数据。在数据库中我存储了车辆ID(主键),车辆时间,车辆类型,车辆长度,车辆速度,轴箱,长度箱,间隙箱等,例如我收集数据从上午10点到12点意味着我将这些数据存储在数据库中,并在下午1点-2点后我需要存储意味着设备包含整个数据,为此我不要我想存储以前的数据,我只需要存储特定的时间数据。

在我的编码下面,当我将列表视图加倍时,我的数据存储在数据库中

Hi

am using Attc device (Automatic traffic counting and classification device) - Namely Phoenix device. in this i want to collect the datas and stored in the database(such that i collected the data's from the device and stored in the database)

I need help from anyone i want to check existing datas in the database if it is already exist i don't want to store the same datas in the database.In the database i stored vehicle id(primary key),vehicle time,vehicle type,vehicle length,vehicle speed,Axle Bin , length Bin,Gap Bin etc for example i collect the datas from 10am-12am means i stored these datas in the database and after 1pm -2pm i need to store means the device contains the whole datas, for that i don't want to store the previous datas i need the particular time datas only to be stored.
Below my coding when i double the list view my datas are stored in the database

private void listView1_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                if (((ListView)sender).SelectedItems[0].ForeColor != Color.Red)
                {
                    FileInfo fi = adp.ReadFilContent(atccDev.ATCCID, ((ATCCFile)((ListView)sender).SelectedItems[0].Tag).FileID,((ATCCFile)((ListView)sender).SelectedItems[0].Tag).IsMMCFile);
                    foreach (EnhancedRawVehicleData data in fi.EnhancedRawVehicleData)
                    {
                        if (data.SensorMissError == SensorMiss.SnMis_NoMiss)
                        {
                            string vehType = "Other";
                            switch (data.NumberOfAxles)
                            {
                                case 2:
                                    {
                                        ;
                                        if ((data.VehAxlesSpacing[0] >= 210) && (data.VehAxlesSpacing[0] <= 309))
                                        {
                                            vehType = " CARS";
                                        }
                                        else if ((data.VehAxlesSpacing[0] >= 310) && (data.VehAxlesSpacing[0] <= 339))
                                        {
                                            vehType = " LGV";
                                        }
                                        else if ((data.VehAxlesSpacing[0] >= 340) && (data.VehAxlesSpacing[0] <= 799))
                                        {
                                            vehType = ".B&L";
                                        }
                                        break;
                                    }
                                case 3:
                                    {
                                        if ((data.VehAxlesSpacing[0] >= 100) && (data.VehAxlesSpacing[0] <= 799)) vehType = "3A-HV";
                                        break;
                                    }
                                case 4:
                                    {
                                        if ((data.VehAxlesSpacing[0] >= 100) && (data.VehAxlesSpacing[0] <= 799)) vehType = "4A-HV";
                                        break;
                                    }
                                case 5:
                                    {
                                        if ((data.VehAxlesSpacing[0] >= 100) && (data.VehAxlesSpacing[0] <= 799)) vehType = "5A-HV";
                                        break;
                                    }
                                case 6:
                                    {
                                        if ((data.VehAxlesSpacing[0] >= 100) && (data.VehAxlesSpacing[0] <= 799)) vehType = "6A-HV";
                                        break;
                                    }
                                case 7:
                                    {
                                        if ((data.VehAxlesSpacing[0] >= 100) && (data.VehAxlesSpacing[0] <= 799)) vehType = "Multi-HV";
                                        break;
                                    }
                                default:
                                    {
                                        vehType = "Other";
                                        break;
                                    }
                            }

                            string str = "{";
                            if (data.VehAxlesSpacing != null)
                            {
                                for (int i = 0; i < data.VehAxlesSpacing.Count(); i++)
                                {
                                    str += string.Format("  {0} cm ({1}')", data.VehAxlesSpacing[i].ToString(),
                                        ConversionUtility.MeterTo(data.VehAxlesSpacing[i] / 100.0, ConversionUtility.DestUnit.feet).ToString("#0.0"));
                                }
                            }
                            str += "  }";
                            string fileName = string.Format("D{0}.{1}-{2}",
                                        atccDev.ATCCID.ToString(),
                                        ((ATCCFile)((ListView)sender).SelectedItems[0].Tag).CreatedTime.ToString("yyyyMMdd.HHmm"),
                                        ((ATCCFile)((ListView)sender).SelectedItems[0].Tag).ModifiedTime.ToString("yyyyMMdd.HHmm")
                                        );
                            string lane = "";
                            SqlConnection con = new SqlConnection("Server=ATTSYSTEMS2-PC;Database=SentosaaVCS;User Id=sa;Password=P@55w0rd;");
                            con.Open();
                            string query = "INSERT INTO VehInfo (DeviceID,RawFileID,LaneID,Lane,VehTime,VehType,VehAxleCount,VehLength,VehSpeed,"
                                            + "VehAxleSpacing,AxleBinID,SpeedBinID,LengthBinID,GapBinID,HeadwayBinID,VehCount) VALUES "
                                            + "('" + atccDev.ATCCID + "','" + fileName + "','" + data.LaneID + "','" + lane + "','" + data.VehSavedTime + "','" + vehType + "','" + data.NumberOfAxles + "'"
                                            + ",'" + (double)data.VehLength + "','" + (double)data.VehSpeed + "','" + str + "','" + 0 + "','" + 0 + "','" + 0 + "','" + 0 + "','" + 0 + "','" + 0 + "')";
                            SqlCommand cmd = new SqlCommand(query, con);
                            cmd.ExecuteNonQuery();
                            con.Close();
                        }
                    }
                    VehiclesData vd = new VehiclesData(fi);
                    vd.Show();
                }



如果在这方面有任何人帮我,我会很高兴的。期待专家的一些好评。







谢谢和问候

Maha

软件工程师


i would be pleased if any one hep me in this regard. expect some favorable answer from experts.



Thanks and Regards
Maha
Software Engineer

推荐答案

如果您正在谈论来自用于跟踪的设备的轮询数据那么

你需要创建



复合键 (点击检查什么是复合键)

使用重要的列,比如说for perticuler vehicle

表示车辆号和投票数据的时间。

表示如果vehicleid = 100已经在下午12:10给出记录,那么当时该车辆的数据将是重复的,因此通过复合键,该记录将不被允许插入数据库。



希望这可以帮到你

;)
if you are talking about polling data coming from device used for tracking Then
you need to create

composite key (click to check what is composite key)
by using your important columns like say for perticuler vehicle
that vehicle number and time of polling data.
that means if vehicleid=100 already given record at 12:10pm then data which wil come for that vehicle at that time wil be duplicate ,so by composite key that record will not be allowed to insert into database.

Hope this may help you
;)


这篇关于Reg:数据库中的现有数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆