|
|
hi all.
I was wondering if anyone can assist me..
I have this code below:
DataTable dtSource = m_dtUsed;
DataTable dtDest = dtSource.Clone();
foreach (DataRow dr in dtSource.Rows)
{
DataRow drNew = dtDest.NewRow();
// this code work perfectly
object[] obj = new object[dr.ItemArray.Length];
dr.ItemArray.CopyTo(obj, 0);
drNew.ItemArray = obj;
dtDest.Rows.Add(drNew);
// why this code can't work?
// after dr.ItemArray.CopyTo(drNew.ItemArray, 0), i find drNew.ItemArray is still empty,i don't know why?
//drNew.ItemArray = new object[dr.ItemArray.Length];
//dr.ItemArray.CopyTo(drNew.ItemArray, 0);
//dtDest.Rows.Add(drNew);
}
Any help would be appreciated.
If we dream, every thing is possible!
modified on Saturday, May 31, 2008 10:13 AM
|
|
|
|
|
What does 'not working' mean ? What does it do instead ? What does MSDN say ?
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 )
|
|
|
|
|
Thanks Christian Graus for your reply.
The issue is :
After "CopyTo" operation, the destination array(here is drNew.ItemArray) is still empty.
If we dream, every thing is possible!
|
|
|
|
|
dealon wrote: // this code work perfectly
object[] obj = new object[dr.ItemArray.Length];
dr.(obj, 0);
That won't even compile.
dealon wrote: // why this code can't work?
//drNew.ItemArray = new object[dr.ItemArray.Length];
//dr.ItemArray.CopyTo(drNew.ItemArray, 0);
//dtDest.Rows.Add(drNew);
The ItemArray property returns a new object array that contains references to the data in the data row. You are copying the data to this array, and then you are throwing it away. Replacing the references in the object array doesn't change the data in the data row.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks Guffa for your help.
I think my incorrect code copied confused you.
The fact is like this:
1)This code can work and the drNew.ItemArray have my wanted data.
------------
object[] obj = new object[dr.ItemArray.Length];
dr.ItemArray.CopyTo(obj, 0);
drNew.ItemArray = obj;
2)But the method below seems bad.
------------
drNew.ItemArray = new object[dr.ItemArray.Length];
dr.ItemArray.CopyTo(drNew.ItemArray, 0);
dtDest.Rows.Add(drNew);
i found drNew.ItemArray is still empty.I don't known why?
If we dream, every thing is possible!
|
|
|
|
|
dealon wrote: i found drNew.ItemArray is still empty.I don't known why?
I already explained why: The ItemArray property creates a new array. Changing anything in that array doesn't change anything in the DataRow. So, you create a new array, fill it with data, and throw it away.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I see.Thank you very much.
If we dream, every thing is possible!
|
|
|
|
|
I'm trying to disconnect socket connection and then want to reuse again when any new client request comes but as I Press disconnect and Re-login then get following Error Message
SocketException was unhandled.
Message:"A blocking operation was interrupted by a call to WSACancelBlockingCall"
ErrorCode:10004
Please help me out how to close socket properly so user re-login again successfully.
Regards,
Shanzay
|
|
|
|
|
It would be hard to guess the exact cause without looking at the code. However the WSACancelBlockinCall exception generally happens when you stop listening as Listen is a blocking method.
Call the Close method to close the connection.
~Dave
Dave Traister
Software Engineer
ComponentOne LLC
www.ComponentOne.com
|
|
|
|
|
Hi,
I want to get byte[] from MultiPage TIFF image.
Have tried out lots of things but not getting solution.
Please suggest me.
Image final; <br />
final = GetMultipageTiffImage();<br />
ImageConverter converter = new ImageConverter();<br />
Byte[] imageByteArray = (byte[])converter.ConvertTo(final, typeof(byte[])); this line is having error. as tiff image is multiple page file.
If doing with below code then also getting same error
byte[] blob;<br />
MemoryStream ms = new MemoryStream();<br />
Image image = GetImage();
image.Save(ms,System.Drawing.Imaging.ImageFormat.Tiff);
blob = ms.ToArray();
Thanks,
Sun Rays
To get something you must have to try once.
My Articles
|
|
|
|
|
What is an image converter ? What does GetMultipageTiffImage do ? Which line has the error ?
Read my image processing articles for info on how to access an images bytes directly.
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 )
|
|
|
|
|
how to adding numbers from multiple textboxes?
|
|
|
|
|
You can't add the numbers as long as they are in the form of strings. You have to convert them to numerical data before you add them.
There are plenty of methods to parse numerical data, like Int32.Parse, Int32.TryParse, Convert.ToInt32, and similar for most numerical data types.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Or he could use VB. At his own risk.
Semicolons: The number one seller of ostomy bags world wide. - dan neely
|
|
|
|
|
Try NumericUpDown instead.
|
|
|
|
|
Could someone clarify a question i have about the code snippet shown below, i know when the useing block ends the OleDbConnection's Dispose method is called, but what i'm not clear on, is the OleDbDataAdapter's Dispose method called also as it is inside the using statement or must I Call it my self? Any information wuold be appreciated.
using (OleDbConnection connection = new OleDbConnection(_connectString))
{
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = new OleDbCommand(_selectCmdText, connection);
// additional processing
}
Thank you in advance.
William T
|
|
|
|
|
I'm pretty sure (unless someone wants to correct me) that everything will dispose of itself accordingly. If you have any connections open though, I'd recommend closing them before everything is thrown through the garbage collector.
Cheers,
|
|
|
|
|
Nope, the adapter.Dispose() will not be called.
The
using (OleDbConnection connection = new OleDbConnection(_connectString))<br />
{<br />
}
is equivalent to
<br />
OleDbConnection connection = new OleDbConnection(_connectString);<br />
try<br />
{<br />
}<br />
finally <br />
{ <br />
connection.Dispose(); <br />
}
If you want to dispose the adapter you must wrap it inside a using, something like this:
<br />
using (OleDbConnection connection = new OleDbConnection(_connectString))<br />
using (OleDbDataAdapter adapter = new OleDbDataAdapter())<br />
{<br />
}<br />
|
|
|
|
|
Hi
I have created a Trigger Statement and assigned to CommandText property of
sqlCommand.While Try to Execute using
command.ExecuteNonQuery() it throws an exception like
{"Incorrect syntax near the keyword 'TRIGGER'."}
Created Trigger Statement:
CREATE TRIGGER SampleTrigger
ON dbo.sample
AFTER INSERT
AS begin
SET NOCOUNT ON
DECLARE @Name AS nvarchar(50)
SELECT @Name= i.Name from inserted i
DECLARE @Address AS nvarchar(50)
SELECT @Address= i.Address from inserted i
insert into triggertest(statusID,FieldName,FieldValue) values( 25,'Name',@Name)
insert into triggertest(statusID,FieldName,FieldValue) values( 25,'Address',@Address)
end
Can anyone help me?
Thanks in advance
Sri
|
|
|
|
|
I don't see anything wrong with it.
You should ask SQL questions in the SQL forum.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I am trying to use SocketOptionName.BlockSource which is a poorly documented socket option. How do I use this option and does it block all packets from an address like I think it does?
I would think that this should work
IPAddress TestIP = IPAddress.Parse("127.0.0.1");
ClassSocK.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.BlockSource, TestIP);
but it does not. I get the fallowing error
"The specified value is not valid.
Parameter name: optionValue"
|
|
|
|
|
Hi!
How can i find out the name of function which is under execution. For example, please see the following code:
void TestFunction()
{
String currentFunctionName = "TestFunction";
}
In the above code, i've hardcoded the name of function in variable currentFunctionName. I want to do that programatically. Please tell me how can i do so. Back during the days of C+, i use __FUNCTION__, please tell me how can i do this is C#. Is it an area of reflection ?
Imtiaz
|
|
|
|
|
StackTrace st = new StackTrace();
string methodName = st.GetFrame(0).GetMethod().Name;
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
string currentMethod = MethodInfo.GetCurrentMethod().Name;
|
|
|
|