i have a text file which has a fixed length lines. How can I update a particular line (record ) basing on a record ID provided? below is my code which retrieves a particular line from the textfile & display it in xtboxes in my update form.: - If System.IO.File.Exists(FILE_NAME) = True Then
-
Dim fs As New FileStream(FILE_NAME, FileMode.Open, FileAccess.Read)
-
Dim sr As New StreamReader(fs)
-
Dim Contents As String = sr.ReadToEnd()
-
Dim strSearch As String = "^(.*?)" & Quest.Text & ""
-
Dim myRegex As New Regex(strSearch, RegexOptions.Multiline)
-
If myRegex.IsMatch(Contents) Then
-
Dim myMatch As Match = myRegex.Match(Contents)
-
Dim theFoundLine As String = myMatch.Groups(0).Value
-
'Display the found line
-
-
Dim splitText() As String = theFoundLine.Split(";")
-
OS01Rec.Text = splitText(0).Trim
-
os01a.Text = splitText(1).Trim
-
OS01b.Text = splitText(2).Trim
-
OS01c.Text = splitText(3).Trim
-
...................... so on
so basically this array holds each field in its respective textbox. Now how to overwrite the textfile???any idea?
Thanks.
5 2324
Basically you should do the same thing that you did reading from it, but using StreamWriter instead of StreamReader.
First of all, make sure you close all open streams when you are done with them, so close your FileStream and StreamReader objects (you should do this as soon as you are done reading from them). When you want to write, create the FileStream again, except with Write permissions instead of Read. Then, make a StreamWriter with that FileStream. Then, use the StreamWriter to write to the file.
Example -
FileStream fs = new FileStream(@"c:\dev\test.txt",FileMode.Open, FileMode.Write);
-
StreamWriter sw = new StreamWriter(fs);
-
sw.WriteLine("Whatever I want to write to the file.");
-
sw.Close();
-
fs.Close();
-
Example -
FileStream fs = new FileStream(@"c:\dev\test.txt",FileMode.Open, FileMode.Write);
-
StreamWriter sw = new StreamWriter(fs);
-
sw.WriteLine("Whatever I want to write to the file.");
-
sw.Close();
-
fs.Close();
-
[/quote]
Thanks for your reply InsertAlias.
But I want only that particular line of my text file to be updated,which was called in the form for updation.This code is overwriting the first line of my text file.It doesnot update that particular ID record . I mean i am getting duplicate lines in my text file (with same ID numbers). Please see below the actual sample of text file:
4;dhl;khush;del ivered;22;33;44 urban;kashif;ma lik;rehman;;;go od;n;;1;2;3;;5; 6;7;8;;0;11;22; 33;;55; 004
3;;multiple;No; done;22;33;44ur ban;kashif;mali k;rehman;Y;N;go od;n;;1;2;3;4;5 ;6;7;22;22;2; 003
2;;multiple;No; done;22;33;44ur ban;kashif;mali k;rehman;Y;N;go od;n;;1;2;3;4;5 ;6;7;22;22;2; 002
The last record is the ID against which we select that line for updation. so only that ID should be updated not others.
Any thoughts? Would be grateful foryour reply.Thanks.
Anyone please. I have to solve this urgently. Thanks in advance for your help.
Well, the way I would solve the problem is to overwrite the whole text file. I'd re-write the things that didn't change as well as what did.
That's one of the problems with using text files instead of databases...les s flexibility.
Well, the way I would solve the problem is to overwrite the whole text file. I'd re-write the things that didn't change as well as what did.
That's one of the problems with using text files instead of databases...les s flexibility.
Boss, How to overwrite the whole file? can you please help me with some code. Thanks.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: laurie |
last post by:
Hi all,
I'm trying to help out a friend who has inherited a client with a PHP
shopping cart application. Neither of us know PHP, but I've been
muddling my way through, trying to get these old scripts working on a
new server with the most recent version of PHP. I've pretty much
taken care of all the various errors that were popping up. Most only
pointed out out non-fatal undefined or assumed variables. I've been
able to cure most of...
|
by: shank |
last post by:
Visually, the page will look somewhat like a spreadsheet. It could have
hundreds of records (rows) displayed. I want to enable the user to edit any
one or any number of records and any fields, then click a save button to
UPDATE the SQL table. I'd like to use stored procedures if possible. How is
this done? Where do I start?
thanks
|
by: Venkat |
last post by:
Hi All,
I need to copy strings from a single dimensional array to a double
dimensional array.
Here is my program.
#include <stdio.h>
#include <stdlib.h>
|
by: Support |
last post by:
<html xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:w="urn:schemas-microsoft-com:office:word"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=windows-1252">
<meta name=ProgId content=Word.Document>
<meta name=Generator content="Microsoft Word 11">
<meta name=Originator content="Microsoft Word 11">
|
by: thangchan |
last post by:
Hi all,
i am getting SQL update problem. as below
======================error messages =======================
Server Error in '/CMS' Application.
--------------------------------------------------------------------------------
無值提供給一或多個必要參數。
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
| |
by: Miro |
last post by:
I will ask the question first then fumble thru trying to explain myself so i
dont waste too much of your time.
Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an
index - i havnt tested the index yet ) so you
can use an .UPDATE( dataTable ) on the data adapter. Otherwise you will
get an exception error.
Is this statement true?
---- Now me fumbling thru
|
by: =?Utf-8?B?RGF2aWRF?= |
last post by:
Hi,
I have to open a text file in c# and read few lines and then I need to
update some lines in the middle of the file. I can read and write by using
the streamReader or streamWriter but I don't know how to read for example
five lines and then update the sixth line and continou to read few lines,
update few etc.
Thanks
David
|
by: Michel Esber |
last post by:
Hi all,
DB2 V8 LUW FP 15
There is a table T (ID varchar (24), ABC timestamp). ID is PK.
Our application needs to frequently update T with a new value for ABC.
update T set ABC=? where ID = ?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |