|
If you are certain that the value you're trying to select exists, this should select it for you. (Bolded lines are lines I've added or changed)
<br />
string selectcmd = "SELECT PostCode FROM `address` group by PostCode ";<br />
adaCP.SelectCommand = new MySqlCommand(selectcmd, MyConn.conn);<br />
adaCP.Fill(dsCP);<br />
cmb_post.DataSource = dsCP.Tables[0];<br />
cmb_post.ValueMember = dsCP.Tables[0].Columns[0].ColumnName;<br />
cmb_post.DisplayMember = dsCP.Tables[0].Columns[0].ColumnName;<br />
<br />
cmb_post.SelectedValue = 2000;<br />
|
|
|
|
|
Great !!
It works
I still have to understand but I'm better
I've spend the afternoon on this
Thank you
|
|
|
|
|
hi every one
am just a beginner in programming languages
so i started with c#
any way i wanna make a simple program to convert from binary to hexadecimal and so on
but I find a problem how to add zero from the lift
am sorry my question is a low level but I really want improve my programming skills
and that will be by ur helps
thank u a lot for interesting
|
|
|
|
|
|
Annoyingly enough, DataColumn.Expression doesn't support bitwise operators, so I decided to do it the long way. Also, annoyingly I can't modulo a double by an int, thus forcing me to convert to int. This leaves me with a column expression that looks like:
Convert((SomeColumn/4),'System.Int32')%2 = 1
Lo and behold my ire as I realize that the Convert function rounds the argument to its nearest whole value. Thus
3/4 = .75
Then:
Convert(.75,Int32) = 1
and
1%2 = 1
This irritates me, especially since I'm trying to work through the DataSet Designer in VS 2k5 and subsequently trying to write as little code as possible.
I've got a couple ideas for working around this - mostly involving writing in my own events or properties - but I'm curious to see if anyone has any other solutions.
|
|
|
|
|
jchalfant wrote: Lo and behold my ire as I realize that the Convert function rounds the argument to its nearest whole value.
3/4 = .75
Sound about right considering int values only hold whole numbers.
|
|
|
|
|
jchalfant wrote: I can't modulo a double by an int, thus forcing me to convert to int
just convert the int to a double then...
I am not sure I understand the problem. (4/4)%2 = 1 is correct. What are you trying to do?
|
|
|
|
|
While C# can handle double % double, ADO.Net expressions can't. I've tried that, no love. Doing so produces a MessageBox at runtime saying
Cannot perform 'Mod' operation on System.Double and System.Double.
What I'm trying to do is get around the lack of bitwise operation support in ADO.Net expressions. In doing so I was hoping to be able to easily bind some control properties to boolean values in a datatable whose values are determined by an expression (somecolumn/somenumber)%2=1. Unfortunately I don't think this is possible.
Oh, and the title, is an oops. What I meant was 3/4%2.
|
|
|
|
|
jchalfant wrote: What I meant was 3/4%2.
That makes sense.
Maybe you can return the boolean values directly in your result set or however you retrieve them.
|
|
|
|
|
That's one of my conclusions.
But what I think I'll do instead is manually add the column to the datarow and evaluate the value based on other column values. I'm not pressed for time on this project, so I've got time to play around and do different things.
|
|
|
|
|
Perhaps you should explain what it is that you are trying to accomplish, rather than asking about why the workaround that you think might be the solution doesn't work as expected...
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Your words of encouragement enlighten me...
To summize what I've already said:
Bitwise operation on the DataColumn Expression property to be used with boolean properties on databound controls.
At any rate, I've determined that it ain't gonna happen through the dataset designer. Any sentiments of wanting to assist are much appreciated.
|
|
|
|
|
Hi,
Not sure why SomeColumn would be a double to start with.
assuming your SomeColumn actually holds an integer value, FIRST convert it to int,
then start processing its bits.
Probably a simple if (intValueOfSomeColumn & 4 != 0) ... does exactly what you want...
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
I wish it were so simple. Datacolumn.Expression, any expression in an activex data object actually, doesn't support bitwise operators.
So, that's no big deal x/y%2 should work. Right? Nope.
ADO.net objects return a double to the engine before computing the modulus. So int/int%2 turns into double%2, which isn't supported. Convert won't work because it performs a Round instead of a cast.
In the end, what I wound up settling on was computing the boolean values as bit fields when I retrieve the data from the database.
|
|
|
|
|
Hi,
Seems to me one of us is not understanding what the other meant.
Either you start with a TYPE double that holds an integer VALUE, then my advice is to
convert it to a TYPE int; that will succeed without problems (unless you exceed the
int's range).
Or your TYPE double holds a non-integer VALUE, and then you will not be able to explain to
me what the meaning of most of its bits is; your question does not make sense in this case.
Did you at all try what I suggested?
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hi,
I wrote a simple code to read a binary file.
It just shows contents of a file as hexadecimal digits.
<br />
using System;<br />
using System.IO;<br />
<br />
class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
FileInfo fi = new FileInfo(args[0]);<br />
BinaryReader br = new BinaryReader(fi.OpenRead());<br />
int offset = 0;<br />
while (br.PeekChar() != -1)
{<br />
if (offset++ % 16 == 0)<br />
Console.Write("\n{0:x8}:", offset);<br />
Console.Write("{0,4:x2}", br.ReadByte());<br />
}<br />
Console.WriteLine();<br />
br.Close();<br />
}<br />
}<br />
And an exception is thrown at PeekChar() method showing messages as follows:
<br />
Unhandled exception: System.ArgumentException: Cannot include the encoded character because of insufficient buffer<br />
Encoding 'Unicode (UTF-8)' (fallback) 'System.Text.DecoderReplacementFallback'.<br />
Argumane name: chars<br />
Location: System.Text.Encoding.ThrowCharsOverflow()<br />
Location: System.Text.Encoding.ThrowCharsOverflow(DecoderNLS decoder, Boolean nothingDecoded)<br />
Location: System.Text.UTF8Encoding.GetChars(Byte* bytes, Int32 byteCount, Char* chars, Int32 charCount, DecoderNLS baseDecoder)<br />
Location: System.Text.DecoderNLS.GetChars(Byte* bytes, Int32 byteCount, Char* chars, Int32 charCount, Boolean flush)<br />
Location: System.Text.DecoderNLS.GetChars(Byte[] bytes, Int32 byteIndex, Int32 byteCount, Char[] chars, Int32 charIndex, Boolean flush)<br />
Location: System.Text.DecoderNLS.GetChars(Byte[] bytes, Int32 byteIndex, Int32 byteCount, Char[] chars, Int32 charIndex)<br />
Location: System.IO.BinaryReader.InternalReadOneChar()<br />
Location: System.IO.BinaryReader.Read()<br />
Location: System.IO.BinaryReader.PeekChar()<br />
Location: Program.Main(String[] args) File D:\CSharp\ConsoleApp\Program.cs:Line 11<br />
I'd like to know what's wrong with my code and what is the right way.
I'm using VS 2005 & .NET framework 2.0.50727
Thanks in advance.
|
|
|
|
|
The file you're reading has unicode characters. Set the encoding to Encoding.Unicode
FileInfo fi = new FileInfo(args[0]);
BinaryReader br = new BinaryReader(fi.OpenRead(), Encoding.Unicode);
int offset = 0;
while (br.PeekChar() != -1)
{
if (offset++ % 16 == 0)
Console.Write("\n{0:x8}:", offset);
Console.Write("{0,4:x2}", br.ReadByte());
}
Console.WriteLine();
br.Close();
Eslam Afifi
|
|
|
|
|
I’ve developed an application that uses a third party ActiveX control for a long time. Now when I run the application on Windows Vista I got the following exception:
at System.Windows.Froms.UnsafeMethods.IOleObject.SetClientsite(IOleClientSite pClientsite)
at System.Windows.Forms.AxHost.SlowActivate()
at System.Windows.Forms.AxHostTransitionUpTo(Int32 state)
at System.Windows.Forms.AxHostCreateHandle()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.AxHost.EndInit()
at System.Windows.Forms.CortonaControl.InitializeComponent()
...
Any idea what’s wrong with Vista?
_____________________________
...and justice for all
APe
|
|
|
|
|
d00_ape wrote: Any idea what’s wrong with Vista?
d00_ape wrote: uses a third party ActiveX control for a long time
Not Vista, get an updated ActiveX control.
|
|
|
|
|
Errm. Why do you think it's a problem with Vista? If a nail punctures your tyre do you think that's a faulty tyre? I would guess that the problem has more to do with the control misbehaving - and Vista's a lot stricter than earlier MS OSes.
|
|
|
|
|
Ok nothing is 'wrong' with Vista but apparently my program that have worked on XP for years does not do that on Vista. Maybe it’s a ‘new feature’ that it does not can use old ActiveX.
By the way, I have one Vista computer that my program works on but the other five cups that I have tried it on does not work.
I don’t really know where I should start searching for help…
I have the same question on http://www.codeguru.com/forum/showthread.php?p=1692586#post1692586
_____________________________
...and justice for all
APe
|
|
|
|
|
Pete O'Hanlon wrote: Vista's a lot stricter than earlier MS OSes
Can I in some way make Vista less stricter on my application?
_____________________________
...and justice for all
APe
|
|
|
|
|
Have you tried to set Vista to run this program as if it were an earlier version of the OS?
|
|
|
|
|
Yes, I have tried Run this program as: Windows XP (Service Pack 2) and as administrator, but same result.
_____________________________
...and justice for all
APe
|
|
|
|
|
Have you tried turning off UAC? Perhaps the ActiveX has a problem when virtualization is active...
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|