|
Hi,
while tranporting from eccel file to datatable all the fields are coming correctly except one field which is not coming if it is having numbers, if it is having string than it also coming correctly.
while other columns are coming correctly in all the cases either it is having string or numbers.
Thanks in advance,
Vijay Kumar
Software Engineer
|
|
|
|
|
Have you fixed this yet?
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
foreach(DataRow dr in dataset.Tables["principal"].Rows)<br />
{<br />
if (dr["name"].ToString()==szPrincipal_name)<br />
{<br />
nPrincipal_Id = Convert.ToInt32(dr["principal_Id"].ToString());<br />
bEncontrou = true;<br />
break;<br />
}<br />
nPrincipal_Id++;<br />
}
_labelRowDeleted:<br />
foreach (DataRow myRow in dataset.Tables["grant"].Rows)<br />
{<br />
if (myRow["principal_Id"].ToString() == nPrincipal_Id.ToString())<br />
{<br />
myRow.Delete();<br />
goto _labelRowDeleted;<br />
}<br />
}
Solutions are welcome.
|
|
|
|
|
How about this?
bool finished = false;
while (!finished)
{
try
{
foreach (DataRow myRow in dataset.Tables["grant"].Rows)
{
if (myRow["principal_Id"].ToString() == nPrincipal_Id.ToString())
{
myRow.Delete();
throw new Exception();
}
}
finished = true;
}
catch
{
finished = false;
}
}
Just an ideea
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
You should NEVER throw an exception unless it is an EXCEPTIONal case (the hint is in the name). This is plainly not an exceptional case. This is an even worse solution to the one that calls goto.
|
|
|
|
|
Bummer8 wrote: _labelRowDeleted:
foreach (DataRow myRow in dataset.Tables["grant"].Rows)
{
if (myRow["principal_Id"].ToString() == nPrincipal_Id.ToString())
{
myRow.Delete();
goto _labelRowDeleted;
}
}
do
{
bool restart = false;
foreach (DataRow myRow in dataset.Tables["grant"].Rows)
{
if (myRow["principal_Id"].ToString() == nPrincipal_Id.ToString())
{
myRow.Delete();
restart = true;
break;
}
}
}
while (restart == true);
Although I'm not entirely sure why you are starting the loop over again when you are deleting a row.
I would imagine the following would have the same effect and be more efficient (by traversing the rows backwards)
DataRows rows = dataset.Tables["grant"].Rows;
for(int i=rows.Length-1; i>=0; i--)
{
DataRow myRow = rows[i];
if (myRow["principal_Id"].ToString() == nPrincipal_Id.ToString())
{
myRow.Delete();
}
}
|
|
|
|
|
try this...
do
{
foreach (DataRow myRow in dataset.Tables["grant"].Rows)
{
if (myRow["principal_Id"].ToString() == nPrincipal_Id.ToString())
{
myRow.Delete();
continue;
}
}
break;
}while(true);
================================
Thanks();
|
|
|
|
|
Why start over every time you find a row? Just store the rows you want to delete, and do it separately.
List<DataRow> removal = new List<DataRow>();
foreach (DataRow row in dataset.Tables["grant"].Rows) {
if ((int)row["principal_Id"] == nPrincipal_Id) {
removal.Add(row)
}
}
foreach (DataRow row in removal) {
row.Delete();
}
---
single minded; short sighted; long gone;
|
|
|
|
|
Well, none of your solutions work. most give errors. Maybe guffa's will, if he get's his code working (<DataRow> <--- what's this supposed to be).
|
|
|
|
|
Templating. a C# 2.0 feature.
--
If you view money as inherently evil, I view it as my duty to assist in making you more virtuous.
|
|
|
|
|
Bummer8 wrote: Maybe guffa's will, if he get's his code working
Gets HIS code working?? Who getting paid to write the code?? Hint, it's NOT Guffa...
Guffa's code works, for .NET 2.0 and above. Apparently you're using .NET 1.1 or below. Colin's will work on .NET 1.1. In either case, they both will work, based on the very limited information you've given. It's up to you to apply the concepts demonstrated to your exact situation.
Buddy, that is what you're getting paid to do!
BTW: Your code looks like it's trying to enforce referential integrity in a database. This is something that's better left up to the database itself.
And, I haven't used a Goto for any reason what-so-ever, in any language, in, what, the last 12 years...
|
|
|
|
|
Hey!
I am trying to set the Enable-property of a toolstripstatuslabel on a statusstrip through an event and I am getting the error message "InvalidOperationException was unhandled, Cross-thread operation not valid....".
On other controls I would solve this by using the control.BeginInvoke() method but there is no such method for a toolstripstatuslabel.
I yes, I want to have CheckForIllegalCrossThreadCalls set to true.
Anyone who has an idea how to solve this?
|
|
|
|
|
I'm not sure what you're taking about but it seems like you want to disable some tool tips from appearing which can be easily archived by excluding them from your controls and adding them again once needed so focus on the associated control not the tooltip itself
and...
Hampus@foi wrote: CheckForIllegalCrossThreadCalls
Is a bad practice in threads so try to skip it by all means!
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
can u pl tell me how to implement custom desktop thro' c#? i want to customize desktop on lan machines..
|
|
|
|
|
You can do it by editing the right registry values, however, for most changes to take place, the user will have to restart.
Smile: A curve that can set a lot of things straight!
(\ /)
(O.o)
(><)
|
|
|
|
|
define custom desktop?
Custom like in Linux KDE GNOME and X-Windows, completely different desktops that are applied as a visual layer to the underlying operating system?
or Custom as in you choose which icons/shortcuts/privileges you permit the users to use?
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
"There is no wealth like knowledge, no poverty like ignorance." Ali ibn Abi Talib
|
|
|
|
|
How to disable the Automatic ToolTip Of TreeView in C# (2003)
venki
|
|
|
|
|
How about TreeView.ShowNodeToolTips=false; ?
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I got this very simple code, now it only works once then it crashes.
If i havent overlooked anything its becuase evertime the OnIncomingMessage event is called it creates a new filestream and streamwriter but i have no idea how to fix this.
It has to create a file, write the message, close the file making it accessable to other programs.
And then when the event is fired again it should do it all over.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Messenger;
using System.IO;
namespace msnincoming
{
public class msnincoming : IMessengerAddIn
{
private MessengerClient _client;
private string _message;
private FileStream _test;
private StreamWriter _test2;
#region IMessengerAddIn Members
public void Initialize(MessengerClient messenger)
{
_client = messenger;
_client.AddInProperties.FriendlyName = "Incoming message alert";
_client.AddInProperties.Creator = "Scale";
_client.AddInProperties.Description = "Alerts Announcer! of new messages";
_client.IncomingTextMessage += new EventHandler<incomingtextmessageeventargs>(this.OnIncomingMessage);
}
#endregion
public void OnIncomingMessage(object sender, IncomingTextMessageEventArgs e)
{
_message = e.UserFrom.FriendlyName + " says " + e.TextMessage;
_test = new FileStream(@"c:\MSNinc.txt", FileMode.CreateNew);
_test2 = new StreamWriter(_test);
_test2.WriteLine(_message);
_test2.Close();
_test.Close();
}
}
}
Thanks!
|
|
|
|
|
MSDN says: "CreateNew: Specifies that the operating system should create a new file. This requires FileIOPermissionAccess.Write. If the file already exists, an IOException is thrown"
You should read the documentation on the types you plan to use!
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- use PRE tags to preserve formatting when showing multi-line code snippets
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Doh, I tought it was that it was trying to create another instance of the streamwriter.
I hate class libary's :P i love debuging.
Thanks!
|
|
|
|
|
Hy,
Can you put in a switch statement anything else besides basic types...i mean can you do something like:
DataColumn dt;
switch(dt)
{
case ...:
case ...:
}
Thanks.
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
No, integral types only (string,int,short,decimal etc)
|
|
|
|
|
Thanks. Back to the drawing board :->
There are 10 kinds of people: those who understand binary and those who don't
|
|
|
|
|
You can as long as the type you are using can be evaluated to a numerical value.
================================
Wirth's law: Software gets slower faster than hardware gets faster.
|
|
|
|