|
|
hi there,
i'm new in programming with C#, does anybody know what is the connecting string ADO.NET for MySQL in C#?
thanks a lot
|
|
|
|
|
Connection strings are language neutral, they have nothing to do with C#.
http://www.google.com.au/search?sourceid=navclient&ie=UTF-8&rlz=1T4ADBS_enAU225AU226&q=MySQL+connection+string[^]
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
|
*Grin* that was the first hit in the google search I linked to
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
|
|
Dear ALL
now i have a LAN + router , and i want to make a software in a certain PC to be able to access the router & get its Configuration & save it to the PC harddisk every a pre-defined period
how could i do that?? the diff. point is how to get the conf. from the router ??
i though of using telnet but i failed to get the router CLI commands to be able comm. with it ( its DLINK ADSL router - DSL-520T - )
any tips
thanks
bye
|
|
|
|
|
I have a representation of a byte stored in a string e.g. "0x08" which I want to convert to a byte.
I must be missing something really obvious here even after googling for 45 minutes.
I have not been able to use byte.Parse("0x08") as this requires an integer.
I tried int.Parse("0x08") but the string cannot be converted so that I could then use the previous method.
Any help appreciated.
Guy
You always pass failure on the way to success.
|
|
|
|
|
You could try:
var number = "0x08";
var integer = int.Parse(number.Substring(number.IndexOf("x") + 1), NumberStyles.HexNumber);
|
|
|
|
|
Thanks - that worked a treat.
All I need to then is:
byte byteCode = byte.Parse(integer.ToString());
and it works.
Thanks again
You always pass failure on the way to success.
|
|
|
|
|
Why do you go via a string? Just convert the integer to a byte:
byte byteCode = (byte)integer;
or:
byte byteCode = Convert.ToByte(integer);
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Good point - I just discovered I get an exception when I try and get an integer above 127.
string tmpByte = "0x80H"
int integer = int.Parse(tmpByte.Substring(tmpByte.IndexOf("x") + 1), System.Globalization.NumberStyles.HexNumber);
Gives me a A first chance exception of type 'System.FormatException' occurred in mscorlib.dll exception.
It's gonna be a late night...
You always pass failure on the way to success.
|
|
|
|
|
Because 08H is not a valid hex number, in any language that I know of . The best way to convert this to a byte (which can hold 0-255) is:
byte converted = 0x00;
bool successful = byte.TryParse(inputString.Substring(inputString.IndexOf("x")), out converted);
if (!successful)
{
MessageBox.Show("Problem!");
}
else
{
}
|
|
|
|
|
Ed.Poore wrote: Because 08H is not a valid hex number, in any language that I know of
It was 80H and it seems valid to a hex converter clickety.
Basically what I am doing is reading in a list of Hex values, provided by Microsoft, of keycodes to be used by keybd_event .
You always pass failure on the way to success.
|
|
|
|
|
The H can be used as a suffix for some programming languages (can't remember which), 0x is the standard C, C++, C# prefix etc. It's just used by the compiler to determine whether it's a hex number or a decimal number. You're getting beyond the range of simple .Substring stuff and moving dangerously close to Regular Expression territory.
|
|
|
|
|
Thanks - I think I've been hit by the stupid stick today.
Been doing too much high level programming and forgot how hex works
I fixed it by limiting the substring to 2 characters.
int integer = int.Parse(tmpByte.Substring(tmpByte.IndexOf("x") + 1,<big>2</big>), System.Globalization.NumberStyles.HexNumber);
Thank you to everyone for their help
You always pass failure on the way to success.
|
|
|
|
|
You could use something like the following code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Globalization;
namespace HexNumbers
{
class Program
{
private static void Main(string[] args)
{
var regex = new Regex(@"(%|&?#|\\x|U\+|=|H'|16#|8'h|#|16r|16#|#x|#16r|&H|&h|$|&|0h|0H)?(?<number>[\d|A-F|a-f]+)('?|#)?(h|H)?", RegexOptions.Compiled);
var numbers = new string[] { "%20", "ꯍ", "#FF", "0x5A3", "\\x1B", "U+20AC", "=D1a", "FFh", "0A3CH", "$5A3", "H'ABCD'", "16#5A3#", "8'hFF", "#01AF", "16r6EF7", "16#ABCD", "#xABC", "&H5A3", "&5A3", "0hA3", "X'5A3'" };
foreach (var number in numbers)
{
var isMatch = regex.IsMatch(number);
if (isMatch)
{
Console.WriteLine("{0} is a match and it's value is {1}", number, int.Parse(regex.Match(number).Groups["number"].Value, NumberStyles.HexNumber));
}
else
{
Console.WriteLine("{0} is not a hex number", number);
}
}
}
}
} Sorry about the length of the expression but is should handle all types of hex number as dictated by the Wikipedia listing for prefixes and suffixes. You could change the + symbol after the (\d|A-F)+ bracket to {2} if you want to limit it to two hex digits.
|
|
|
|
|
|
Well if I knew the restrictions that you're placing on the data it could be greatly simplified but thought I'd cater for as much as I could.
|
|
|
|
|
Out of interest Ed (and forgive me, I'm a little bit pissed), but why the "var" on Regex and numbers?
|
|
|
|
|
It's a new feature in C# version 3.
It's needed for when you are using anonymous types in LINQ.
It can also be used to make the code easier to read if the data type that you are declaring is obvious from the context, like:
var cmd = new System.Data.SqlClient.SqlCommand(query, connection);
instead of repeating the data type:
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(query, connection);
However, Ed is using it everywhere, even when the data type is not obvious from the context, which instead makes the code harder to read.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Guffa wrote: However, Ed is using it everywhere, even when the data type is not obvious from the context, which instead makes the code harder to read.
That's what I thought 
|
|
|
|
|
Guffa wrote: However, Ed is using it everywhere, even when the data type is not obvious from the context, which instead makes the code harder to read.
Cos me is lazy
Besides It's very rare anyone else looks at my code so I tend to use it out of habit because I don't have a problem remembering what type a variable is. The name is usually enough if I don't remember straight away. Besides the IDE makes it easy enough to check.
|
|
|
|
|
That's fine when you are playing with yourself, but it doesn't make good example code.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|