|
Hi All,
I have a problem combining results of two queries. The queries are fired on the same table with the same select list, only the where condition changes. It would be better if i show what i actually want.
This is my table data for example.
Field1 Field2
AB 1
SD 2
SDFG 3
AS 4
QWE 5
BBG 6
I want an output as
Field1 Field2
AS 4
QWE 5
BBG 6
AB 1
SD 2
That means , if i give the value for Field2 = 3 in the query then the result will not contain record with Field2 = 3 and the result should display the record with Field2 > 3
first and the with Field2 < 3 both sorted in ascending order.
I am using the union operator for combining results, but the results are not as desired. Also i feel that the union clause is not efficient since it takes about 4-6 secs to fetch the records.
Is there any efficient solution for my problem. Please reply soon as i have already spent considerable time on this query and i am running short of time now.
Any help will be appreciable.
Thanks in Advance.
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
SELECT field1, field2
FROM table1
WHERE field2 > @someNumber
UNION
SELECT field1, field2
FROM table1
WHERE field2 <= @someNumber
The only problem is the order by clause is applied to the entire union at the end. So we need to cheat a little
SELECT field1, field2, 0 as ignoreMe
FROM table1
WHERE field2 > @someNumber
UNION
SELECT field1, field2, 1 as ignoreMe
FROM table1
WHERE field2 <= @someNumber
ORDER BY ignoreMe ASC, field1 ASC, field2 ASC
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
Thanks Alot Ennis Ray Lynch, Jr. !
It worked fine.
But can u suggest something about, how can this query be optimized ?
"A good programmer is someone who looks both ways before crossing a one-way street." -- Doug Linder
Anant Y. Kulkarni
|
|
|
|
|
The only optimization is to index field 2 and field 1. I don't know your server hardware but it is a simple query and should be instant on data sets less than 100,000 records. I just tested it on our oracle box and 6.5 million records takes 29 seconds.
A man said to the universe:
"Sir I exist!"
"However," replied the Universe, "The fact has not created in me A sense of obligation."
-- Stephen Crane
|
|
|
|
|
An interesting problem:
I have a ListView with LabelEdit set to TRUE. When I change the label, I want to make some decisions as to whether the ListViewItem (that's just been edited) should stay in the ListView or not.
The natural place to inspect this is in the AfterLabelEdit event...
If the decision is to take the item out, I used the ListViewItem.Remove().
However - check this out:
A) say that the item's index is N (indices are zero-based)
B) if there exists an item after it (i.e. with index N+1)
then this item gets quietly removed
C) if the item is the last in the list,an exception is thrown
saying that index N (requested to be removed) is non-existant.
It looks like:
D) when the item is being edited, it is taken OUT of the
ListView.Items collection. So - the original item N+1 moves up and
is temporarily assigned index N (that is how it gets removed - see
B) above)
E) if however, item N is the last in the collection and gets
temporarily taken out while being edited, then of course we get
and exception thrown as there isn't an item with index N
This can easily be proved:
1. create a new Windows Forms project
2. add a ListView to the form
3. Set LabelEdit to TRUE
4. Add 3 items to the list, with labels e.g. 'Item1', 'Item2' and 'Item3'
5. Create a handler for the AfterLabelEdit event
6. Inside this handler add this code:
ListViewItem item = listView1.Items[e.Item];
item.Remove();
7. Run the application
8. Edit the first item and press Enter -> the second item is removed
9. Next, edit the last item then press Enter -> exception is thrown
This is all very nice...
But - can someone suggest an elegant workaround , i.e. - where and
how can I remove items after they have been edited?
Many thanks in advance.
alekyork
|
|
|
|
|
What you are trying to do will work if you set e.CancelEdit = true befor removing the the item: in the AfterEdit handler:
e.CancelEdit = true;
listVew1.Items[e.Item].Remove();
We need to graduate from the ridiculous notion that greed is some kind of elixir for capitalism - it's the downfall of capitalism. Self-interest, maybe, but self-interest run amok does not serve anyone. The core value of conscious capitalism is enlightened self-interest.
Patricia Aburdene
|
|
|
|
|
We have a DataGridView which is bound to a dataset and has a DataGridViewCheckBox cell that is used to select a row. It is done this way because the user must select which rows of data will be released to the next stage of processing.
The DataGridViewCheckBox (naturally) is not bound.
I have an event handler that is trapping the ClickEvent on the box as follows:
private void HandleCheckedEvent(object sender, DataGridViewCellEventArgs e)
{
if ( !m_formLoaded ) return;
else if ( m_functionCode != "E01" ) return;
else if ( e.ColumnIndex != 0 ) return;
DataGridViewCheckBoxCell currentCell = ( ( DataGridView )sender ).Rows[ e.RowIndex ].Cells[ e.ColumnIndex ] as DataGridViewCheckBoxCell;
if ( currentCell == null )
return;
else
DetermineButtonState( (DataGridView)sender, currentCell, e.RowIndex );
}
Right now the DetermineButtonState method just throws up a MessageBox showing me the state of the currentCell. When I run the code the Value of the cell is ALWAYS NULL! How can I properly manage if someone checks or unchecks a box at the time it happens???? According to MSDN the click event sends me the event just before the value is set so it seems that the first click being null should be fine. The second (uncheck) event, though, should be showing a currentCell.Value of True and the next (check) event should show me a currentCell.Value of False. Why is it NULL???? How do I get around this???? Is it okay to kill the developer that wrote this control???
Thanks for any help.
|
|
|
|
|
Is currentCell null because it is not of type DataGridViewCheckBoxCell? Or is it null because ...Cells[e.ColumnIndex] is actually null?
|
|
|
|
|
The currentCell.Value was null because it was not persisting the value.
After digging into things I was going to write my own control that would guarantee the state is maintained. Then when I went to see what existed for Notes to Inheriters I found code that showed what I had to do.
It turns out that I cannot check the state of the checkbox with only a single event. I have to do it in two events.
First binding to the datagridview.CurrentCellDirtyStateChanged and force the control to persist the data with cell.CommitEdit. That indirectly forces the datagridview.CellValueChanged event which now allows me to investigate the cell state value.
I now have everything working as expected !!!
|
|
|
|
|
Hi.
Does anybody know if it is possible to write programatically a text in a web application page with functionnalities like "newline", "tab", "center text",...
In fact: organise a text programatically before putting it in a web page.
Thanks,
Oren
|
|
|
|
|
You can write text and format it with normal html controls. Then u can add this to one of the block-level element( , etc).
Example:
1. Type the following script in notepad and save it in wwwroot folder with name such as "Test1.aspx"
2. Open Internet Explorer and the type URL: http://localhost/Test1.aspx
<script runat="server">
Sub Page_Load(sender As Object,e As EventArgs)
Dim str As String="<h1><center> Welcome To Web<b/> Appplication </center></h1> in <br /> <h3>ASP.NET</h3>"
div1.InnerHtml=str
End Sub
</script>
<html>
<head>
</head>
<body>
A Simple Test<br />
<form runat="server">
<p id="div1" runat="server" />
</form>
</body>
</html>
I dont know wheather may reply solve ur problem. However i just tried.
|
|
|
|
|
You can write text and format it with normal html controls. Then u can add this to one of the block-level element( , etc).
Example:
1. Type the following script in notepad and save it in wwwroot folder with name such as "Test1.aspx"
2. Open Internet Explorer and the type URL: http://localhost/Test1.aspx
<script runat="server">
Sub Page_Load(sender As Object,e As EventArgs)
Dim str As String="<pre><h1><center> Welcome To Web<b/> Appplication </center></h1> in <br /> <h3>ASP.NET</h3> "
div1.InnerHtml=str
End Sub
A Simple Test
|
|
|
|
|
You can write text and format it with normal html controls. Then u can add this to one of the block-level element( , etc).
Example:
1. Type the following script in notepad and save it in wwwroot folder with name such as "Test1.aspx"
2. Open Internet Explorer and the type URL: http://localhost/Test1.aspx
<script runat="server">
Sub Page_Load(sender As Object,e As EventArgs)
Dim str As String=<pre>"<h1><center> Welcome To Web<b/> Appplication </center></h1> in <br /> <h3>ASP.NET</h3>"
div1.InnerHtml=str
End Sub
A Simple Test
|
|
|
|
|
sorry for inconvience. The browser is parsing data section. The contents of str varaible are as under:
<h1><center> Welcome To Web<b/> Appplication </center></h1> in <br /> <h3>ASP.NET</h3>
|
|
|
|
|
You can use StringBuilder to build text before dumping on a label, literal or straight Response.Write() . Or you can look at HtmlTextWriter which has some specific methods for HTML writing (obviously), though it doesn't facilitate newline or tab.
-- modified at 10:47 Friday 28th July, 2006
I take that back, HtmlTextWriter does handle indent and newline.
|
|
|
|
|
Thanks guys, I'll try what you proposed tomorow (on sunday) when I'll be back at my project computer. Here, I don't have Visual.
Oren,
|
|
|
|
|
|
Take a look at the NotifyIcon class.
"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 www.troschuetz.de
|
|
|
|
|
This might help you out.
http://msdn.microsoft.com/coding4fun/inthebox/systrayalclock/default.aspx
-K
|
|
|
|
|
I have an fixed length array :-
Byte[] myArray = new Byte[50];
Now this represents a specific message structure. For example, the sort of thing I want to do is :
1. to read and set a bit field, Byte[25], bit 1
2. to read and set a 5 bit value, Byte[20], bits 0-5
3. to read and set a 32 bit number, Byte[10]
These are just a few examples of what functions I want to perform on the array. But they highlight some of my challanges.
Any thoughts on gneral ways to achieve this?
Thanks,
Liam
|
|
|
|
|
Well, to set a particular bit in a byte, I would use bitwise operators. The exclusive-or (^) would work:
byte b = 35;
b ^= 0x01;
*Note - This will change the value of the bit. If it's 0, it will be changed to 1, if it's 1 it will be changed to zero.
Of course, it's hard to tell what you mean by bit 1. But to set a particular bit in the byte array is not much different:
byte[] b = new byte[50];
...
b[25] ^= 0x01;
To read the value, you can use a bitwise-and ( & ) :
if (b[20] & 0x1f == a) { ... }
I'm not sure what you mean by setting a 32 bit number on a single byte though.
Logifusion[^]Last modified: Friday, July 28, 2006 9:43:29 AM --
|
|
|
|
|
forgive me - I'm new to c#
public struct lookupOjbect
{
string fieldvalue;
public lookupOjbect (string fieldvalue)
{
this.fieldvalue = fieldvalue;
}
}
lookupOjbect lookupObjectRow = new lookupOjbect();
When I want to assign a value to this object then 'fieldvalue' doesnt show with intellisense. e.g. lookupObjectRow.fieldvalue - doesnt show!
|
|
|
|
|
it is because fieldvalue is private.
Try
public string fieldvalue
though that is not great oop, and most thing use properties to get around that and keep encapulation, e.g.
private string fieldvalue;
public string FieldValue
{
set { this.fieldvalue = value; }
get { return this.fieldvalue; }
}
|
|
|
|
|
|
Remember that changing the values in a struct type only affect that particular instance as it is a value type.
If you are planning on implementing a Get / Set accessor, you may want to think about using a class instead.
|
|
|
|