|
Try "select * from Win32_PhysicalMedia" and see if that returns values. I'm surprised the code even compiles because mp["Name"] will return an object. Try. mp["Name"].ToString(), mp["MediaType"].ToString()...
Also don't forget to dispose of the ManagementObjectSearcher pd.
"You get that on the big jobs."
|
|
|
|
|
Hello Everybody,
I am trying to develop an application for Internet Access Watcher( URL Monitor).For that i am Listening socket.
it returns some data but i m not able to convert it read only (URL Address) format.
so please help...
byte[] input = BitConverter.GetBytes(1);
byte[] buffer = new byte[4096];
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
s.Bind(new IPEndPoint(IPAddress.Parse("192.168.5.6"), 0));
s.IOControl(IOControlCode.ReceiveAll, input, null);
int bytes = 0;
do
{
bytes = s.Receive(buffer);
if (bytes > 0)
{
Console.WriteLine(Encoding.ASCII.GetString(buffer, 0, bytes));
}
} while (bytes > 0);
Thanks
If you can think then I Can.
|
|
|
|
|
eg_Anubhava wrote: it returns some data
What data? How do you expect anyone to figure out what you are receiving and what you expect to receive from reading the above?
I must get a clever new signature for 2011.
|
|
|
|
|
I want the URL which is currently displayed in browsers address bar.
Like : www.google.com
If you can think then I Can.
|
|
|
|
|
eg_Anubhava wrote: I want the URL which is currently displayed in browsers address bar.
Then I think you will have to hook into the browser and read the text out of that field. There are many articles on this process here on CodeProject.
I must get a clever new signature for 2011.
|
|
|
|
|
Since every browser has a different control layout and does not expose the same programming interface, if at all, you have no choice but to implement your own proxy server to monitor what each client is doing. Or, just use one off-the-shelf.
|
|
|
|
|
I have tested ToString() on a few decimal and it looks nice with no trailing zero, i.e.
1m.ToString() => 1
1.1m.ToString() => 1.1
1.0001m.ToString() => 1.0001
Yet, in my app, I have some decimal.ToString() looking like 5.00000000000000 (many useless trailing 0) which crops up all over the place!
Any idea as to why!?!
[Edit]
mmm.... in fact I was wrong! decimal store the number of decimal value it has been created with a display them!
i.e.
1.0m.ToString() => 1.0
(1.0m * 1.0m).ToString() => 1.00
User error, oops...
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.
|
|
|
|
|
Insufficient information! Show us the code and values that lead to your conclusion, and don't forget to include the relevant declarations.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
dunno, those decimal value come from the database!
mm... maybe I should check the values in the database...
but they do get displayed as "5.0000000000000000", anyway I just write a utility method which remove trailing 0
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.
|
|
|
|
|
that is not the solution, as later on you will perform a search with a "WHERE field = 5" and the result set will not be what you expect. IMO when you have a problem you should try and understand and solve it, rather than hide it.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
mm.... there is some sense in that, let's roam this damn database!!!
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.
|
|
|
|
|
Hey, by looking at the database I just got some idea!
while
1m.ToString() => 1
decimal.Parse("1.0000000").ToString() => 1.0000000
how strange....
but thankfully
1m == decimal.Parse("1.0000000") => true
mmm.... in fact I was wrong! decimal store the number of decimal value it has been created with a display them!
i.e.
1.0m.ToString() => 1.0
(1.0m * 1.0m).ToString() => 1.00
User error, oops...
but the conclusion: it's ok to remove the 0!!!
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.
|
|
|
|
|
So we both learned something today.
I tried a few things, and it seems the number of decimals can only increase.
When I multiply two numbers and show the result with ToString() I am getting (using decimal variables everywhere):
2 * 0.5 = 1.0
2.0 * 0.5 = 1.00
so multiplication adds the number of decimals of both multiplicands and propagates that to the product.
my conclusions would be:
1. there is a small difference between numbers, even when they have identical values (as in 1.0 and 1.00)
2. if you want to avoid all irrelevant trailing zeroes, you'd have to remove them explicitly.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Luc Pattyn wrote: so multiplication adds the number of decimals of both multiplicands and
propagates that to the product.
If memory serves me right it has to do with accuracy in physics when multiplying.
I should look that up when I have the time, but there was some logic behind it
V.
|
|
|
|
|
Super Lloyd wrote: Any idea as to why!?!
Because of the formatting of an imprecise type. Your doing calculations in your app with those decimals?
Look up the formatting-specifier on MSDN and use when appropriate. If you only want "a few", then specify that. Like "2".
I are Troll
|
|
|
|
|
I thought the whole point of decimal was to avoid this kind of problem!
I don't want to truncate to 2 number after the dot. I want to show the whole current value without any useless 0 (more user friendly).
Some of them are cents per litre, the user would be confused by calculations results if I remove some non zero digits!
Anyway, I "fixed" it, made a function to remove trailing '0'
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.
|
|
|
|
|
Super Lloyd wrote: I thought the whole point of decimal was to avoid this kind of problem!
Might be, but it still can't guess how much decimals you want. Hence, it'll probably take the one that "fits best".
Super Lloyd wrote: Anyway, I "fixed" it, made a function to remove trailing '0'
So, it might still result in a value of 1,0000001?
I are Troll
|
|
|
|
|
Eddy Vluggen wrote: So, it might still result in a value of 1,0000001?
Indeed!
I want no insignificant 0, but as many relevant number as possible!
Think accounting!
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.
|
|
|
|
|
Super Lloyd wrote: I want no insignificant 0, but as many relevant number as possible!
A zero isn't insignificant, it means that the value at that position is zero. There's a huge difference between 1 and 1.0 in terms of knowledge - the latter one is more precise. Numbers are relevant up to the specified precision.
I are Troll
|
|
|
|
|
The documentation states that. "The scaling factor also preserves any trailing zeroes in a Decimal number. Trailing zeroes do not affect the value of a Decimal number in arithmetic or comparison operations. However, trailing zeroes can be revealed by the ToString method if an appropriate format string is applied".
I guess this behaviour is what makes dealing with decimals more accurate by avoiding some of the issues regarding doubles.
"You get that on the big jobs."
|
|
|
|
|
Hey, I didn't read the documentation carefully enough! :P
Anyway, one reason decimal are more human and accountant friendly is that number are stored as ... decimal! I.e. the same representation we used to read / write!
I.e. every 4 bits is stored a number between [0 8[
unlike float and double which are a sum of a power of 2 values...
they are also much slower!
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.
|
|
|
|
|
hi guys...i get some informations from a site Xml file and convert that file to DataTable and then save it in my form's load..it works well but the problem it works very very slow..when i clicked the button to open my form it takes one min almost to open it..how can i make it faster to work..here is the codes i wrote...
public XmlNodeList XmlListesi()
{
XmlDocument doc = new XmlDocument();
doc.Load("http://cekilis.millipiyango.gov.tr/haftalik_loto_bilgileri.xml");
XmlElement root = doc.DocumentElement;
XmlNodeList elemlist = root.GetElementsByTagName("haftalik_loto_bilgileri");
return elemlist;
}
public DataTable ConvertXmlNodeListToDataTable(XmlNodeList xnl)
{
DataTable tablo = new DataTable();
int TempColumn = 0;
foreach (XmlNode item in xnl.Item(0).ChildNodes)
{
TempColumn++;
DataColumn dc = new DataColumn(item.Name, System.Type.GetType("System.String"));
if (tablo.Columns.Contains(item.Name))
tablo.Columns.Add(dc.ColumnName = dc.ColumnName + TempColumn.ToString());
else
tablo.Columns.Add(dc);
}
int ColumnsCount = tablo.Columns.Count;
for (int i = 0; i < xnl.Count; i++)
{
DataRow dr = tablo.NewRow();
for (int j = 0; j < ColumnsCount; j++)
{
try
{
dr[j] = xnl.Item(i).ChildNodes[j].InnerText;
}
catch (Exception)
{ }
}
tablo.Rows.Add(dr);
}
return tablo;
}
public void InsertSayisal(DataTable dt)
{
cmd = dal.InsertSayisal();
cmd.Parameters.AddWithValue("@cek_no", System.Data.SqlDbType.Int);
cmd.Parameters.AddWithValue("@cek_tarih", System.Data.SqlDbType.NVarChar);
cmd.Parameters.AddWithValue("@num1", System.Data.SqlDbType.NVarChar);
cmd.Parameters.AddWithValue("@num2", System.Data.SqlDbType.NVarChar);
cmd.Parameters.AddWithValue("@num3", System.Data.SqlDbType.NVarChar);
cmd.Parameters.AddWithValue("@num4", System.Data.SqlDbType.NVarChar);
cmd.Parameters.AddWithValue("@num5", System.Data.SqlDbType.NVarChar);
cmd.Parameters.AddWithValue("@num6", System.Data.SqlDbType.NVarChar);
cmd.Parameters.AddWithValue("@altibln", System.Data.SqlDbType.NVarChar);
cmd.Parameters.AddWithValue("@besbln", System.Data.SqlDbType.NVarChar);
cmd.Parameters.AddWithValue("@dortbln", System.Data.SqlDbType.NVarChar);
cmd.Parameters.AddWithValue("@ucbln", System.Data.SqlDbType.NVarChar);
cmd.Parameters.AddWithValue("@alti_ikr", System.Data.SqlDbType.NVarChar);
cmd.Parameters.AddWithValue("@bes_ikr", System.Data.SqlDbType.NVarChar);
cmd.Parameters.AddWithValue("@dort_ikr", System.Data.SqlDbType.NVarChar);
cmd.Parameters.AddWithValue("@uc_ikr", System.Data.SqlDbType.NVarChar);
for (int i = 0; i < dt.Rows.Count; i++)
{
cmd.Parameters["@cek_no"].Value = dt.Rows[i][0].ToString();
cmd.Parameters["@cek_tarih"].Value = dt.Rows[i][1].ToString();
cmd.Parameters["@num1"].Value = dt.Rows[i][4].ToString();
cmd.Parameters["@num2"].Value = dt.Rows[i][5].ToString();
cmd.Parameters["@num3"].Value = dt.Rows[i][6].ToString();
cmd.Parameters["@num4"].Value = dt.Rows[i][7].ToString();
cmd.Parameters["@num5"].Value = dt.Rows[i][8].ToString();
cmd.Parameters["@num6"].Value = dt.Rows[i][9].ToString();
cmd.Parameters["@altibln"].Value = dt.Rows[i][10].ToString();
cmd.Parameters["@besbln"].Value = dt.Rows[i][11].ToString();
cmd.Parameters["@dortbln"].Value = dt.Rows[i][12].ToString();
cmd.Parameters["@ucbln"].Value = dt.Rows[i][13].ToString();
cmd.Parameters["@alti_ikr"].Value = dt.Rows[i][14].ToString();
cmd.Parameters["@bes_ikr"].Value = dt.Rows[i][15].ToString();
cmd.Parameters["@dort_ikr"].Value = dt.Rows[i][16].ToString();
cmd.Parameters["@uc_ikr"].Value = dt.Rows[i][17].ToString();
try
{
cmd.ExecuteNonQuery();
}
catch (SqlException)
{
}
}
}
vemedya.com
|
|
|
|
|
Hi,
I don't have the answer, I do have a lot of questions and some suggestions:
1.
how many rows and columns are in your DataTable?
2.
why are you swallowing exceptions? it is dumb to do so, as it hides potential or real problems you are having. Log them to a log file, and look at it. Don't use MessageBoxes, they are just annoying. Use at most one, at the end of an operation, to say something went wrong and more details are in the log file.
3.
why are you storing almost everything as a string? it wastes time and disk space, and it probably hampers functionality too.
4.
why are you repeating the same operations all the time? e.g. I see lots of dt.Rows[i] you would better fetch the row once and keep it in a local variable.
5.
I can't tell how long dal.InsertSayisal() should take, you should look into that method too.
6.
you could use a StopWatch to get timing information, and log that to your log file, together with some extra information; that way you could see how your code behaves, i.e. where exactly time gets wasted.
7.
if, I don't know, your DataTable's only purpose is to get the XML data to the database, then maybe you would be better off doing it in a single loop, one row at a time, avoiding the need to keep everything in memory at once. (Depends on #1).
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Use XmlTextReader instead of XmlDocument. XmlDocument will sit there reading and indexing the whole document before you can start working with it. XmlTextReader will stream the data so you can work while it is reading. Just note XmlTextReader is harder to work with.
"You get that on the big jobs."
|
|
|
|
|
Ditch the DataTable . Ditch all those ToString s.
|
|
|
|