我只想更新CSV文件中现有行的1列 [英] I want to update only 1 column of an existing row in CSV file

查看:94
本文介绍了我只想更新CSV文件中现有行的1列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个移动应用程序,通过该应用程序,我只需要更新qty列.
也就是说,如果扫描了条形码,则它将在.csv文件中进行搜索;如果条形码中不存在文件,则它将更新整个行,如下所示

Hi Everyone,

I have one mobile application through which i need to update the qty column only.
That is if a barcode is scanned then it will search in .csv file, if the barcode is not present in file then it will update the entire row as below

Dim sr As StreamWriter = File.AppendText("\Application\" & createHfile)
                   quantity = quantity + 1
                   mWriteData = "" & Now.Date & "," & dr(1) & "," & quantity & ""
                   sr.WriteLine(mWriteData)
                   sr.Close()
                   txtserialno.Text = ""



但是如果再次扫描相同的条形码,则它已经存在于.csv文件中,因此在这里我需要将数量从"1"更新为"2",而不是插入新行.

在此先感谢



But if the same barcode is scanned again then it is already present in .csv file, so here i need to update the quantity from ''1'' to ''2'' instead of inserting the new row.

Thanks in advance

推荐答案

无法在文件系统中更新"文件.您需要复制整个文件.在某些类中可能存在一些看起来可以进行更新的方法,但它们仍在重写整个文件.因此,您需要更改内存中的整个文件,然后将其写到文件系统中,或者找到一个为您隐藏详细信息的类.

IMO最好的选择是将地图保存在扫描对象的内存中,以便可以在它们存在时对其进行更新,然后根据需要将其值写到文件系统中.
There is no way to ''update'' a file in the file system. You need to copy over the whole file. There may be methods in some classes that look like they can do an update, but they are still rewriting the entire file. So, you need to change the entire file in memory, and write it out to the file system, or find a class that hides the details for you.

Your best bet IMO is to keep a map in memory of objects scanned, so you can update them if they are already there, then write out the values to the file system as often as you need to.


这篇关于我只想更新CSV文件中现有行的1列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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