|
Hi
Just try this code
foreach (DataRow row in dt.Rows)
{
int colcount = dt.Columns.Count;
for(int i = 0; i<colcount; i++)
{
if ((row[i] == null || row[i].ToString() == ""))
{
foreach (DataRow row1 in dt1.Rows)
{
row[i] = row1[i].ToString();
}
}
}
}
dt is datatable1 and dt1 is datatable2
Regards
Naina
Naina
|
|
|
|
|
Hello,
I have a fixed XML table thats coming from a Web Service.
<Loan>
<Name>JOHNSON, DANIEL R.</Name>
<Number>BMRES-550</Number>
<BankName>Bank of America</BankName>
<ClosingNo>123456</ClosingNo>
<FundsToSendAmt>49,7560.8600</FundsToSendAmt>
</Loan>
I need to convert the XML data to CSV. The data to be converted has commas. So the below method doesn't work:
using (StreamWriter writer = File.CreateText("C:\\username\\password\\Desktop\\Export.csv"))
{
DataSet ds = new DataSet();
ds.ReadXml(XmlReader.Create(new StringReader(myWebreference.GetWebServiceMethod("username", "password1", "Export", "Parameter4", DateTime.Today, DateTime.Today, ""))));
writer.WriteLine(string.Join(",", ds.Tables["Loan"].Columns.Cast<DataColumn>().Select(col => col.ColumnName).ToArray()));
foreach (DataRow row in ds.Tables["Loan"].Rows)
{
writer.WriteLine(string.Join(",", row.ItemArray.Cast<string>().ToArray()));
}
}
|
|
|
|
|
Why not convert comma's to something that wont be in your data like ~ ?
Frazzle the name say's it all
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
John F. Woods
|
|
|
|
|
Actually this might be more what I'm looking for:
public class WireEntry
{
public String Name { get; set; }
public String Number { get; set; }
public String BankName { get; set; }
public String ClosingNo { get; set; }
public WireEntry()
{
}
}
foreach (DataRow row in ds.Tables["Loan"].Rows)
{
WireEntry newEntry = new WireEntry();
newEntry.Name = row["Name"].ToString();
newEntry.Number = row["Number"].ToString();
newEntry.BankName = row["BankName"].ToString();
result.Add(newEntry);
}
return result;
|
|
|
|
|
Maybe I am wrong but you still need to strip out the comma's from the incoming data. Or possibly I didn't understand your task.
I was thinking string.Replace(",","comma");
Frazzle the name say's it all
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.
John F. Woods
|
|
|
|
|
What do you do with the CSV when you're done? Why use CSV?
0) Use a different delimiter (Good).
1) Wrap the values in quotes (better).
2) I'd prefer to save the XML and then use XSLT to form the CSV.
|
|
|
|
|
Actually thats a good question. Because I'm not really wanting the end file to be a CSV file. The end file should be in FedWire Format.
http://www.frbservices.org/campaigns/remittance/files/fedwire_funds_format_reference_guide.pdf[^]
I just figured it would be easier to get to my end result with a CSV file to work with.
Basically I'm taking that Web Service. Iterating through the tables. Then ultimately spitting out a file in that format.
{1015} blah blah blah {1870} blah blah blah
|
|
|
|
|
Cut out the middlemen (including the DataSet).
Look into XSLT to transform the XML to FedWire directly. I can probably help, but I won't read that document until I get home.
|
|
|
|
|
Hmmm Ok. Thanks for the brainstorming. Guess i dont need a dataset at all if XLST can give me both displaying the data in a meaningful manner front end while also being able to convert the data and spitting it out to a file, which it sounds like it can. I look into it until you get back to me.
|
|
|
|
|
RickSharp wrote: The end file should be in FedWire Format.
The posted link is not a Protocol structure document. It looks like a mapping document.
|
|
|
|
|
Normal form for "CSV" is to put double quotes around values that have commas.
With double quotes the value is also surrounded by double quotes and each double quote in it is then escaped with two double quotes.
|
|
|
|
|
When the tabpage added the form in it, and the tagpage resize, the form can't fill the tabpage. i haved setup the form.dock = dockstype.fill, but seem that is no usefull. any one can gave me clue?
Examples.
Form2 form = new Form2();
TabPage tbPage = new TabPage();
tbPage.Text = "test";
tbPage.Name = "page1";
tbPage.BackColor = SystemColors.ControlText;
Panel panel = new Panel();
panel.Dock = DockStyle.Fill;
tbPage.Controls.Add(panel);
tabControl.TabPages.Add(tbPage);
form.TopLevel = false;
form.Parent = panel;
form.Show();
tabControl.SelectedTab = tbPage;
|
|
|
|
|
Well, you can achieve this, and here's an example:
public partial class Form1 : Form
{
public Form1(){ InitializeComponent();}
private Form form2 = new Form();
private Panel pnl1 = new Panel();
private Button btn1 = new Button();
private TabPage tbPg1 = new TabPage();
private void Form1_Load(object sender, EventArgs e)
{
pnl1.BackColor = Color.SlateBlue;
pnl1.Padding = new Padding(32);
form2.TopLevel = false;
form2.FormBorderStyle = FormBorderStyle.FixedSingle;
form2.ControlBox = false;
form2.MaximizeBox = false;
form2.MinimizeBox = false;
form2.Text = "";
form2.BackColor = Color.Azure
form2.Resize += (ob, ea) =>
{
btn1.Location = new Point((form2.Width/2) -(btn1.Width/2),
(form2.Height/2) - (btn1.Height/2));
};
form2.Parent = pnl1;
form2.Dock = DockStyle.Fill;
form2.Visible = true;
btn1.AutoSize = true;
btn1.BackColor = Color.WhiteSmoke;
btn1.Text = "button on the Form";
form2.Controls.Add(btn1);
btn1.Click += (ob, ea) => { MessageBox.Show("Button on Form Clicked"); };
tbPg1.BackColor = Color.LightSteelBlue;
tbPg1.Text = "Test Form in Panel in TabPage";
tbPg1.Padding = new Padding(32);
tbPg1.Controls.Add(pnl1);
pnl1.Dock = DockStyle.Fill;
tabControl1.Controls.Add(tbPg1);
}
}
But, I wonder: why are you inserting a Form in a Panel which is then inserted in a TabPage ?
In general, you should not be using a Form inside any other Container Control, including another Form: Forms are "heavy-weight" .NET objects, and really are not meant to be used this way.
Yes, .NET WinForms will let you "get away with it," but that does not mean it is good practice. If you really need to design the contents of TabPages in their own designer, outside of the TabControl itself, why not use a UserControl, a "lighter-weight" object ?
To change from using a Form, to using a UserControl in the above example, is as simple as making these changes to the code:
1. private UserControl form2 = new UserControl();
... of course, being a good programmer, you will change form2's name to something more mnemonic !
2. comment out the following four lines in the Form_Load EventHandler, like this:
//form2.FormBorderStyle = FormBorderStyle.FixedSingle;
//form2.ControlBox = false;
//form2.MaximizeBox = false;
//form2.MinimizeBox = false;
If you share something about your design goals here, I'd be happy to respond with suggestions, and I am sure that other CP Members will also respond.
yrs, Bill
|
|
|
|
|
Hello,
I've an application which reads and writes to a shared excel using C#.
The application runs on different computers and whenever anybody writes to the excel a pop-up appears on all the computers in which the application is running and displays the recent message written to excel file.
I am using FileSystemWatcher and an event is raised whenever something is written to the file.
If this event occurs I am reading the excel file from each of the process and displaying the latest message.
Now, when I am reading the excel file from different computers(processes) at the same time. All the processes does not get the latest message.
I am opening the excel in readOnly and releasing the excel object successfully.
Also, I have found that when many processes are trying to read from the same excel at the same time. The excel tends to crash.
I have added a thread.sleep(3000) so that there is a delay in reading the excel file. This did help but still the excel throws error messages.
Is there anyway that I can read excel file one after the other from each process?
|
|
|
|
|
what is the error message? or COM exception code?
Is there any inner exception?
These are valuable tips on what the problem could be!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
|
It sounds like you are taking every step possible to overcome some very common problems with network shares.
The FileSystemWatcher and sleep(3000) may not be enough. Try creating a locked file (FileStream with Non-Sharing Mode) that your "listeners" try to access. Remove the lock once the message has been added and the excel file is written.
But my guess is that you will never get rid of this problem. File access using network shares are never reliable when accessed from multiple computers simultaneously (in my experience).
|
|
|
|
|
Hello.
iam trying to read a KeyValuePair but it seems that iam doing soemthing wrong here, iam including a small part of the code where iam trying to read the value and also a capture from the debug, the debug shows me in "Locals" the info that i want to read.
var dataSourceName = (
from entry in entityParams
where entry is KeyValuePair<string, string> && entry != null && ((KeyValuePair<string, string>)entry).Key.Equals("DataSourceName")
select ((KeyValuePair<string, string>)entry).Value).FirstOrDefault();
I did not find a way to upload and include a image in this post, so i added it external instead.
Link to image
In this debug case its the value "ps3" that i need.
I have added the .dll switchking.common to my references and also
using SwitchKing.Common.Entities;
But now i need help what i need to do more to have access to the value.
|
|
|
|
|
It's not clear what yout problem is, but it looks like your criteria is to look for KeyValuePair<string, string=""> whereas the data is another type (KeyValuePair)(no generic clause! different type!)
BTW a let statement will make things cleaner
(
from entry in entityParams
let kv = entry as KeyValuePair
where kv != null && kv.Key = "DataSourceName"
select kv.Value
)
.FirstOrDefault();
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Thanks for the reply.
this is the error message that i receivs if i runt the code you posted.
The as operator must be used with a reference type or nullable type ('SwitchKing.Common.Entities.KeyValuePair' is a non-nullable value type)
|
|
|
|
|
You forgot to mention it's a compiler error!
mm... KeyValuePair is a value type!
the 'as' operator doesn't work with value type, because
'obj as type' evaluate as null is obj is not of type type, which is not possible with value type (they can't be null!)
scrap the 'as' too bad, try
(
from entry in entityParams
where entry is KeyValuePair
let kv = (KeyValuePair)entry
where kv.Key == "DataSourceName"
select kv.Value
)
.FirstOrDefault();
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Thanks for the help, that solved my issue.
|
|
|
|
|
hi guys
i want connect and disconnect to internet by exist connection in the c#
how can i connect and disconnect to internet by exist connection in the c# ?
please guide me
thanks a lot
|
|
|
|
|
What do you mean "connect to internet"? You need to know what destination you are going to connect to, and how you will communicate to it. Please give some more detail of your problem.
One of these days I'm going to think of a really clever signature.
|
|
|
|
|
apadana_1989 wrote: how can i connect and disconnect to internet by exist connection in the c# ?
You can't using the standard definition of the terms you are using.
By definition if you close a connection it is done. It can't be used again.
Guessing what you might really want...
If you want the client box to have a single connection then you could connect to another server, and use it as an intelligent proxy to issue commands for you. So that server does the connect/disconnect and just redirects traffic to the client. But the server MUST exist for this to work.
If you are referring to a wireless/VPN/modem 'connection' via which your client app tunnels IP traffic then normally it stays up anyways. But if you want to control it explicitly because it is closing then you would need to get the API for that specific thing (wireless/VPN/modem) and control it yourself.
|
|
|
|