|
Works in ie, no go in FF, that's the sort of thing I'm looking for though thanks!
I have no blog...
|
|
|
|
|
I have a database query that will, for purpose of discussion, return either 1, 2 or 3 results. It could be any of these sizes.
I also have an array with 3 values in it. This is fixed.
I want to loop from i = 0 to 2 and compare a field's value from query row i to the value in array row i and do something if they match and do something different if they don't.
However, since I will always be looping 3 times and sometimes my query result will only have 1 or 2 rows in it, how do I check to see if the query row index exists before I go forward with the comparison?
Something along the lines of IfExists(mydata.Rows[0]) == TRUE is what I'm looking for. Any ideas? Thanks in advance! -Kari
|
|
|
|
|
store 1,2 and 3 in ArrayList.
Arraylist has one method to check value is contains or not.
Arr.Contains(mydata.Rows[0]);
bEST rEGARD
pATHAN
---------------------------------------------------
|
|
|
|
|
if you are using SqlDataReader then you can use
SqlDataReader datareader = dataCommand.ExecuteReader();
int i = 0;
while (datareader.Read())
{
if (datareader.GetByte(0) == array[i])
{
}
i++;
}
Becoming Programmer...
|
|
|
|
|
I'm programming in c#.
I' have a problem with database insert procedure. I need read the last record in a table because I need the last key and insert a new record with key + 1.
For this procedure I open connection, select the last key, insert the new key and close conncetion.
The problem message is: There is already an open DataReader associated with this Command which must be closed first.
How to make this insert without leave the database? I can problem with the concurrent coneections.
Thanks.
Diego
|
|
|
|
|
You should close your DataReader object before executing the code that performs your insert.
BTW, this doesn't look like the most efficient way of adding a new record. You should consider wrapping the whole operation in a stored procedure that selects the latest key to determine the new key value and then inserts the new record with this key.
Paul Marfleet
|
|
|
|
|
do you have an example of this operation? thanks
|
|
|
|
|
and you want to ensure you have sufficient locking on the table, for both the read and the write. If two people perform the same operation at the same time, they might both be given the same 'new' key.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."
|
|
|
|
|
Hello,
I'm hoping someone can help me out here.
I want to get started using DataGridView, but I've not actually managed to find any examples that fit what I'm trying to do.
What I want to do is very simple:
(1) I have a list of class instances thus:
<br />
List<MyClass> classList = new List<MyClass>();<br />
<br />
classList.Add(new MyClass("Fred"));<br />
classList.Add(new MyClass("Wilma"));<br />
<br />
etc
(2) I want each MyClass member of classList to be represented as a row in my DataGridView
(3) I want to show only a subset of the class parameters, for example:
<br />
public class MyClass<br />
{<br />
private string name;<br />
private string desc;<br />
<br />
private int anumber;<br />
<br />
public String Name<br />
{<br />
get { return (name); }<br />
set { name = value; }<br />
}<br />
public String Description<br />
{<br />
get { return (desc); }<br />
set { desc = value; }<br />
}<br />
<br />
<br />
<br />
public int Number<br />
{<br />
get { return (anumber); }<br />
set { anumber= value; }<br />
}<br />
}<br />
I understand that I need to set the DataSource parameter of my DataGridView to my data, in some way, but I don't seem to be able to get it to work. Do I need to do something to my classes to get it to work?
I think that sums it up. No SQL, nothing just a nice list of data that I want to display.
Can anyone help? Many thanks!!
|
|
|
|
|
Hi,
Use a binding source to bind your list and then bind the binding source to the data grid view.
dataGridView1.DataSource = bindingSource1;
dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
this.bindingSource1.DataSource = myList;
Thanks and Regards
Mahen
|
|
|
|
|
Please don't cross post. You asked this same question only two hours ago. It is rude to cross post just because no one answers right away.
"Try asking what you want to know, rather than asking a question whose answer you know." - Christian Graus
|
|
|
|
|
And even ruder to then delete the mail leaving you dangling in the forum!
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"This time yesterday, I still had 24 hours to meet the deadline I've just missed today."
|
|
|
|
|
Malcolm Smart wrote: even ruder to then delete the mail leaving you dangling in the forum!
Yeah, those are pretty bad, too.
"Try asking what you want to know, rather than asking a question whose answer you know." - Christian Graus
|
|
|
|
|
hi there,
i put a progress bar in my app, its working well, but when i click outside the app then app becomes white, that mean it look like the non responding prog. but its working in backgroud
i wanna know how can i make it that it should look working app?
Becoming Programmer...
|
|
|
|
|
To xmen_xwk,
you can use "Application.DoEvent();" at each loop.
---------------------------------
Believe what you saw!
|
|
|
|
|
thanks dude
Becoming Programmer...
|
|
|
|
|
Use a backgroundworker to do the work, which can then report progress to the gui thread so you can update the progress bar
I have no blog...
|
|
|
|
|
I new C# programmer and I'm attempting to write a FAST generic method that would takes types like short, int, long, float, double etc.... and put them in a byte array at a specified index. It would allow you to specify the endianess you want. I have seen a couple of answers out on the forums, but they all appeared to be handing the of data (or byte arrays)several times. I could define the same method with the specific type I want use and it will compile but then I need to duplicate this for every type that I want to use. I was hoping I could get some help on this so the method is both fast and easy to maintain.
The following is what I would like to do but it doesn't compile because "Cannot take the address of, get the size of, or declare a pointer to a managed type ('T')":
public unsafe static void IntoBytes2 <T> (byte[] byteArray, int index, T data, bool MSBFirst) where T : struct
{
byte* dataPtr = (byte*)&data;
if ((index + sizeof(T) - 1) <= byteArray.Length)
{
if (MSBFirst)
for (int i = index + sizeof(T) - 1; i >= index; i--, dataPtr++)
{
byteArray[i] = *dataPtr;
}
else
for (int i = index; i < index + sizeof(T); i++, dataPtr++)
{
byteArray[i] = *dataPtr;
}
}
}
Thanks for any help
- Nick
|
|
|
|
|
My first question would be why are you trying to reinvent the wheel?? This is already possible in the .NET Framework using the BitConverter class and Serialization using the BinaryFormatter.
|
|
|
|
|
That would perfect if the byte array was in little endian byte order. However, the data that I'm looking at is in big endian format.
Example:
The byte array looks like this: { 0, 0, 0, 1, 0, 0, 0, 3} and I need to convert the first four bytes into a 0x1 and the next four bytes into a 0x3.
I know I could do it with bitConverter and then reversing a temp array and then storing back into the original, but thats a lot of data movement.
I want to keep this as effecient as possible.
It would have been great if they would have supplied a boolean option to the BitConverter to state what kind of byte order your dealing with for input (from byte array) or output (to an array).
I very new at C# so please be patient with me (as my name suggest).
Thanks,
Nick
|
|
|
|
|
|
Ahh, you beat me to it!
|
|
|
|
|
So what I'm hearing (from the article) there is no good (and fast) solution other than possibly using the System.Net.IPAddress.HostToNetworkOrder/NetworkToHostOrder which appears will work for 4 bytes or less (shorts, int); but will it work for values that are stored in 8 bytes (doubles)?
Even with the host/network order if your class already has an byte [] defined you'll now you have to copy the return getbytes array into it!
This sure would have been so much easier if they supplied a flag parameter on the getbytes and other BitConverter routines. Along with a new method (same as getbytes) but returns a void and updates a destination array at a specified index for a value that you pass it: example: BitConverter.PutByte(destArray, destIndex, value, reverseEndianess);
I definetly use the network/host order To<type> to at least convert my bytes to a value. Still wondering if it will work for doubles?
Thanks.
|
|
|
|
|
I thought the host/network was a toggle for endianess. It's not. I didn't look at the source code but I suspect is basically doing the same thing that was mentioned in the article. And it will only work for 4 byte and 2 byte values.
Any other ideas? Otherwise I guess I will just un-generic my code and keep duplicating as needed.
(Sucks!)
|
|
|
|
|
Hi guys,i hope to learn how i can create a new textbox with checkbox or button.i want to create in same form.i want when i click button or checkbox ,form create a new textbox
|
|
|
|