C#读取数据库以获取上一条记录,然后开始读取文本文件以进行下一条记录 [英] C# read database for last entry and then start reading text file for next record

查看:235
本文介绍了C#读取数据库以获取上一条记录,然后开始读取文本文件以进行下一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个接收器Windows应用程序,它从客户端向我发送一些提要的端口(逻辑端口)接收流.
我的接收器接收到提要并将其写入文本文件.

我还有另一个应用程序,该应用程序读取文本文件进行解析并将其转储到mysql数据库中.

如果由于某些原因,如果我必须停止(关闭)我的应用程序,该应用程序将数据转储到数据库中并重新启动它.重新启动应用程序后,我想读取之前在阅读时保留的文本文件.
我的意思是说,如果我从1000个文本文件中读取了100行,由于某种原因,我必须关闭我的应用程序.
现在,我再次启动我的应用程序,并希望从101行开始.

波纹管是文本文件格式

Hi all,
i have a receiver windows application which receives stream from a port (Logical port) on which my clients is sending me some feed.
my receiver receives the feed and write it in to a text file.

I have an other application which reads the text file parse it and dump it in to mysql database.

if for some reasons if i have to stop (close) my application which dumps data in to database and restart it. after restarting the application i want to read the text file where i left it while reading it before.
i mean to say that if i have read 100 lines from text file out of 1000 and for some reasons i have to close my application.
now i start my application again and want to start from 101 line.

bellow is the text file format

"31/07/12 11:31:18","GOLD-OC12","","TRD","","",""

"31/07/12 11:31:18","GOLD-OC12","","ORD","49433","50","49485","50","",""

"31/07/12 11:31:18","GOLD-OC12","","TRD","","",""

"31/07/12 11:31:18","GOLD-OC12","","ORD","49435","50","49485","50","",""

"31/07/12 11:31:18","GOLDKILO-OC12","","TRD","","",""

"31/07/12 11:31:18","GOLDKILO-OC12","","ORD","49403","5","49454","5","",""

"31/07/12 11:31:18","GOLDKILO-OC12","","TRD","","",""

"31/07/12 11:31:18","GOLDKILO-OC12","","ORD","49405","5","49454","5","",""

"31/07/12 11:31:18","GO100OZ-OC12","","TRD","1622.5","1","5"

"31/07/12 11:31:18","GO100OZ-C12","","ORD","1622.4","50","1622.8","50","1622.5","1"

"31/07/12 11:31:18","GO100OZ-OC12","","TRD","1622.5","1","5"

"31/07/12 11:31:18","GO100OZ-C12","","ORD","1622.4","50","1622.8","50","1622.5","1"

推荐答案



我们不确定您的应用程序如何工作,但是我做出一些假设,为您提供了一种解决方案.

假设
1)每个文本文件都有一个日志条目
2)您具有包含所有数据的单个文本文件.
注意:如果以上假设不正确,甚至其他解决方案也是可能的.

解决方案
-您可以检查数据库表记录,然后直接在该行上开始阅读.如果您在从特定位置读取文本文件时遇到问题,请告诉我.

例如:您的数据库中有100条记录,然后从101中读取文本文件,您的应用程序将再次将数据转储到数据库中.

希望它对您有用,如果您有任何疑问,请通知我.

谢谢
-Amit Gajjar
Hi,

We are not sure how your application is working, but making some assumption i am giving you one solution.

Assumptions
1) each text file have single log entry
2) you have single text file having all data.
Note : even other solutions are possible if above assumptions are incorrect.

Solution
- You can check your database table records and go directly on that line and start reading. Let me know if you have problem with reading text file from particular position.

ex : you have 100 records in your database then read your text file from 101 and your application will again dump data in database.

hope it works for you, Let me know if you have any query.

Thanks
-Amit Gajjar


您的意思是保存最后一行.在应用程序何时何地开始检索该行号,
读取文本文件的行仅一个,直到计数器达到行号.表示如果counter> = line_no,则在数据库中添加条目

您可以存储Line-no三种方式.
1.在数据库中
2.在全局应用程序中,用户定义的属性(settings.designer.vb页面)
3.在注册表项中.

处理完该行后,不要忘记增加行号并更新它的状态(数据库或全局应用程序用户定义的属性或注册表项-您使用的任何源).

祝您编码愉快!
:)
you mean to save last line no. some where and when application start retrieve that line no.,
read text file''s lines on by one and nothing to do till counter reaches the line no. means if counter>= line_no then add entries in database

you can store Line-no three ways.
1. In database
2. In global application user-defined property (settings.designer.vb page)
3. In Registry key.

do not forget to increase line-no and update it''s status in (database or global application user-defined property or registry key - any of source you used) when you have processed the line.

Happy Coding!
:)


这篇关于C#读取数据库以获取上一条记录,然后开始读取文本文件以进行下一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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