|
M Riaz Bashir wrote: Dear Respected Programmer
:->
M Riaz Bashir wrote: Kindly send me the method or Source Codes that How to use Crystal Report 10 in C# 2005 and which references are needed in design time.
Try Google[^]
|
|
|
|
|
Is there an easy and efficient way in C# to read a file in blocks, remove all carriage return & line feed characters from the read block and write the remaining block into another file?
I've tried FileStream, StreamReader and StringBuilder without success. I'm obviously missing something here, being a newby in C#.
VagaBond
|
|
|
|
|
Hy,
Try this:
//reading from the file.txt
FileStream fstream = File.Open("file.txt",FileMode.Open);
byte []buffer = new byte[fstream.Length];
fstream.Read(buffer,0,buffer.Length);
string message = System.Text.Encoding.ASCII.GetString(buffer);
message.Replace("\n","");
fstream.Close();
//writing fileSave.txt
fstream = File.Open("fileSave.txt",FileMode.Create,FileAccess.Write);
buffer = System.Text.Encoding.ASCII.GetBytes(message);
fstream.Write(buffer,0,buffer.Length);
fstream.Flush();
fstream.Close();
You use the Replace method to replace the CRLF. If this doesn't work only with replacing '\n', try replacing '\r' too.
There could be another way in this example. In the byte array "buffer" search for 13(ascii decimal value for CR) and 10(LF) values that are sequential. If you find these values delete them from the byte array
Do your best to be the best
|
|
|
|
|
Hi Karkster,
You're the man!!! It works. Thanks a million, pal...
VagaBond
|
|
|
|
|
If you use the ReadLine method, it reads up to a newline, but does not read the newline.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi,
When adding anything new record, for example a new car, is it always wise to validate the input parameter?
The code that I have is as follows:
public static int InsertCategoryGroup(Car objCar)
{
// Validate parameter
if (objCar == null)
throw (new ArgumentNullException("objCar"));
}
Is this the correct way to do it, or is there a better way? Am I throwing the correct exception, or is there more that I need/can throw. Please can someone comment.
Regards,
ma se
|
|
|
|
|
Hy,
Throwing exception is a good way to validate parameters. You could try to create new Exceptions. If you don't want to write code that catches exceptions you can validate the parameter in the InsertCategoryGroup function and if the parameter does pass the validation step just return an error code (like -1).
Do your best to be the best
|
|
|
|
|
karkster wrote: just return an error code (like -1).
Awful advice in .NET! Error codes mean nothin, have no context, no stack trace no message. Use exceptions!
---
How to get answers to your questions[^]
|
|
|
|
|
Hi,
I agree with you.
This is how I code. I work like this:
.aspx page --> BLL class --> DAL class --> BLL class --> .aspx page
In my stored procedure I usually do a test to see if a record has been inserted or updated. To test for an inserted record success, my code is:
-- Check for insert error
IF (@@ERROR <> 0)
BEGIN
SET @ErrorCode = -1; -- SQL Server error
GOTO CleanUp;
END
-- Commit transaction
IF (@TranStarted = 1)
BEGIN
SET @TranStarted = 0;
COMMIT TRANSACTION;
END
RETURN 0;
So if there happens to be an error it will return a -1. Now in my returned parameter, how do I throw this exception based on -1???
Please advise.
Regards
ma se
|
|
|
|
|
The way you are doing it is spot on, and is also the MS best practice way, provided you always expect to have a car object supplied to your method.
The golden rule is that exceptions should only be used for exceptional circumstances, and not as a general means of controlling execution flow.
Regards,
Rob Philpott.
|
|
|
|
|
I'm using the method NetworkStream.Read to receive data from Network.
But this method is a blocking method. That's why I put this
method in a new thread.
If there are no data, then it will be halted here (NetworkStream.Read).
How can I abort this method, for example if I close my application ?
|
|
|
|
|
Hy,
If you have the reading method in a separate thread the best way to cancel the reading is to kill the thread or abort it. You can try also to write something like:
int bytesRead = 0;
while ( (read = stream.Read(......)) !=0 )
{
//Process data
if (!stream.DataAvailable)
break;
}
Hope it helps
Do your best to be the best
|
|
|
|
|
For the thread to be killed when you close the application, all you need to do is set the IsBackground[^] property to true. For other situations, the best way is to use a flag to check if the thread is to be aborted, before attempting the next Read.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Hello
I want to convert a string variable to Standard Time. My string is a personal time like "15:00" , How can i convert it to DateTime variable ?
Thank you
-- modified at 3:24 Wednesday 12th July, 2006
|
|
|
|
|
|
Hello again
Dear stancrm
But this code just returns current date without time !!!
I have to convert my string time to standard DateTime because I want to do some jobs like add 10 minutes to that or ...
please help.
|
|
|
|
|
I just tried it and it return current date and the time from your input.
For example :
DateTime d = DateTime.Parse("15:00");
Console.WriteLine(d.ToString());
Then you will see : 12.07.2006 15:00
|
|
|
|
|
You can use DateTime.Parse("15:00"). But in VS2005, it is better to use DateTime.TryParse(...). It is because,according to my info, if DateTime.Parse can't convert string to DateTime, it will throw exception. But DateTime.TryParse(...) will return boolean that indicates whether String is converted to DateTime and DateTime as second out parameter of TryParse. If it can't, it will simple return false.
Regards,
Wasif Ehsan.
|
|
|
|
|
Hello. I want to change an item from a datarow belong to a dataset. I tried below code but I couldn't. I have a dataset (ds) and I filled it from a database. Each row has two item and there are for example name and surname.How do I change an item. I want to code like below.
ds.Tables[0].Rows[0]..... = "aaaaaa";
Thanks.
|
|
|
|
|
|
try to use
ds.Tables[0].Rows[0]..... = "aaaaaa";
ds.Tables[0].AcceptChanges();
rahul
|
|
|
|
|
I tried below codes. It didn't show any error message but It couldn't change the value.
MessageBox.Show(ds.Tables[1].Rows[0].ItemArray[1].ToString());
ds.Tables[1].Rows[0].BeginEdit();
ds.Tables[1].Rows[0].ItemArray[1] = "akutumm";
ds.Tables[1].Rows[0].AcceptChanges();
MessageBox.Show(ds.Tables[1].Rows[0].ItemArray[1].ToString());
|
|
|
|
|
Use following:
ds.Tables[0].Rows[0][Column_Name]="aaaa";
Regards,
Wasif Ehsan.
|
|
|
|
|
|
hello all!
how to monitor the running processes while some virus/spyware is attacking on the system.
and what application/program is consuming what resources of the system.
muhammad mahmood ilyas
|
|
|
|