|
Muammar© wrote: What's so wrong with that??
You have more data than columns.
Muammar© wrote: Any better practice??
Yes, of course.
You are not performing any validation on the data in the reader whatsoever. This is bad, very bad, in fact you can't believe how mind bogglingly massively bad that is....
Always validate your input, whether from a user interface control, a file on a disk or the database. If there is the possibility that the information could be wrong or tampered with you should validate it.
If you are sure the line should be correct you should code in a way that aids debugging. You should extract the line from the file into its own variable, and use the debugger to check what it is.
You should split the string up into another varialbe and use the debugger to tell you what is in that.
You should never just dump the result of a chained set of method calls as the parameter to another method call unless you can GUARANTEE that it won't break or have unexpected results. You cannot make that guarantee, so don't do it!
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
string[] tokens = line.Split(',');
dt.Rows.Add(tokens);
}
In the above sample, use the debugger to check what is in line and tokens . Is it what you expect? Is it doing something you didn't expect? What is it doing that is wrong? How would you correct that?
|
|
|
|
|
Colin Angus Mackay wrote: This is bad, very bad, in fact you can't believe how mind bogglingly massively bad that is....
I'm sorry but definitely I'm not using such code, I just took out a quick an modified snippet to make my post short, when I said "better practice" I meant the data storage/manipulation process, I mean, are dataRows/dataColumns and dataTables are the best?? Any tips to make the process faster than doing it this way?
Thanks anyways Colin, you got my five for taking the time to help
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
Just read your posts on Extension Methods and Mixins -- very good.
I'm still not enthusiastic about Extension Methods for a number of reasons, one of which is that I wanted finer-grained control over including them.
What I did with one last week was to put the extension method in a namespace that contains only that method (or family of methods) and is named for that method, so I can do something like:
using PIEBALD.Lib.LibExt.IsNullOrEmpty ;
to only include those extension methods that I intend to use.
|
|
|
|
|
Wrong number!
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
"You're not thinking four-dimensionally." -- Emmett Brown
|
|
|
|
|
Hi,im bit new to .net and Now im stucked in this matter for few days!!
If Some one can help me,it will be great!!
What i want to do is,Im loading data to the left side listBox as follows
//Loading the AssistanceType
DataTable dtAssistanceType = ((MasterUI)this.ParentForm).ObjRemoteObject.VoTBL.GetAssistanceType();
ArrayList arAssis = new ArrayList();
arAssis.Add(dtAssistanceType);
lstTypeofAssistanceLeft.DataSource = dtAssistanceType;
lstTypeofAssistanceLeft.DisplayMember = "AssistanceType";
lstTypeofAssistanceLeft.ValueMember = "AssistanceTypeID";
Assistance[] ass = new Assistance[] { };
lstTypeofAssistanceRight.DataSource = ass;
lstTypeofAssistanceRight.DisplayMember = "AssistanceType";
lstTypeofAssistanceRight.ValueMember = "AssistanceTypeID";
And then ,when i press a button,i want to add the selected item to the right listBox and get the ValueMember (ID) of the selected value!!
I did it like this,
DataRowView dr = (DataRowView)lstTypeofAssistanceLeft.SelectedItem;
Assistance objAss = new Assistance();
//objAss.AssistanceTypeID =Convert.ToInt16(dr["AssistanceTypeID"].ToString());
//objAss.AssistanceType = dr["AssistanceType"].ToString();
lstTypeofAssistanceRight.Items.Add(lstTypeofAssistanceLeft.SelectedItem);
objAss.AssistanceTypeID = Convert.ToInt16(dr["AssistanceTypeID"].ToString());
objAss.AssistanceType = dr["AssistanceType"].ToString();
int id = Convert.ToInt16(lstTypeofAssistanceRight.SelectedValue);
But when i did like this,it doesn't give any ID!!!
But if i bind a data source to LeftlistBox,it wont allow me to add items!
If i didnt bind the dataSource it wont give the ID.
Anyone knows the solution for this???
Thanks alot!!!
|
|
|
|
|
I got the solution!!!
we can create a dataRowView object(objDV) and fill it with the selected item of the left list box!!and add the objDV to the rightListBox!!
So we can set the disply member and the value member!!
and get the ValueID!!
|
|
|
|
|
hello forum
i want to know the full form of CSV and what the full concept is
regards
rahul
|
|
|
|
|
|
That first link was very informative; thanks!
|
|
|
|
|
Glad to help you
|
|
|
|
|
Hi Rahul,
CSV is for Comma-separated values. CSV files are just like an excel. CSV is mainly use to import/export huge data in SQL. You can notice in some websites "Export to excel" link, if you click this link a file will be downloaded, which will be actually a CSV file (we use CSV due to its fastness and quick response).
Thanks
Be a good professional who shares programming secrets with others.
|
|
|
|
|
Mohammed Hameed wrote: CSV files are just like an excel
Well, no not really. A true Excel file (.xls) is not a csv file.
Mohammed Hameed wrote: "Export to excel" link, if you click this link a file will be downloaded, which will be actually a CSV file
Sometimes.
An Excel file is of a very specific format. A csv file is simply a comma delimited file which can be read by Excel or any number of other applications.
if you type bob,the,coder into notepad and save it you have a csv format file.
Hope this helps
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi,
I have create a deployment project in Visual Studio 2005. How do I set icon that displays in the Add/Remove program for my application?
Thanks
|
|
|
|
|
Select your Deployment Project > properties > AddRemoveProgramsIcon "the first item in the list"
Then browse for your icon "should be imported first"
All generalizations are wrong, including this one!
(\ /)
(O.o)
(><)
|
|
|
|
|
i made 3 form . form1,form2,form3.
form2 is mdiContainer . when i open the form1 and form3 from form2..........
it opens , i want that when i click to open a new form it should check that wheather any form is opened
or not. if a form is already opened ,new form should not been opened.....
Maifs
|
|
|
|
|
If you want one and only one instance of a class then you need to hide the constructor and use a static method or property to return the single instance:
class foo
{
private static foo bar;
private foo()
{
}
public static foo barHandle()
{
if (bar == null)
{
bar = new foo();
}
return bar;
}
}
cake, piece of.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
If form1 and form3 are child forms, you can iterate through form2's MdiChildren to check before opening.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Expect everything to be hard and then enjoy the things that come easy. (code-frog)
|
|
|
|
|
Hi friends,
How can we do off/disable/suspend to the undo of the system
So that action and data would not go to undo stack.
e.i
If undo is off and user write some text in a notepad or delete any file.
Than user could not do undo,since it is not in undo stack.
Any type of help will be appreciated.
Thanks in advance.
Regards,
Khaleek Ahmad
|
|
|
|
|
how to change system time using c# code.please help
|
|
|
|
|
|
Hi all,
i have athe following Crc16 method. I want to use it in my C# application but am not sure how to go about it. Can anyone please put some light on this issue.
short int crc16(char *pBuf, short int Len, short int InitialCrc){
short unsigned int crc=0, i=0;
crc = 0;
for (i = 0; i < Len; i++ ) {
crc = (crc >> 8) | (crc << 8);
crc = crc ^ *pBuf;
crc = crc ^ ((crc & 0xff) >> 4);
crc = crc ^ (crc << 12);
crc = crc ^ ((crc & 0xff) << 5);
pBuf++;
}
return(crc);
}
Many thanks in advance
Regards,
The only programmers that are better that C programmers are those who code in 1's and 0's
Programm3r
My Blog: ^_^
|
|
|
|
|
First you have to decide how you want to handle the characters. A character in C++ is 8 bits, while a character in C# is 16 bits.
After that, the translation is pretty straight forward.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
|
Programm3r wrote: The other problem is how can I convert string to char*
string foo = "Hello World";
fixed (char* fp = foo)
{
var i = crc16(fp, (ushort) foo.Length, 0);
}
|
|
|
|