|
abbd wrote: there are an exception
That's because there is an error.
If you tell which exception, I can tell you which error.
Well, in this case I can actually tell you anyway. You are reading the items as if they were arrays, but they are strings.
foreach (object ee in myList) { MessageBox.Show((string)ee); }
Unless you are stuck with framework 1, you should use a List<string> instead of ArrayList , so that you don't have to cast every item to string when reading from the list.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Alternatively you can iterate through the elements of an ArrayList like that:
for(int i = 0; i < myList.Count; i++)
MessageBox(myList[i]);
|
|
|
|
|
I have 20000 lignes of string and i would construct a txt file , i make this :
StreamWriter Fichier;
Fichier = File.CreateText(@"C:\CSV1.txt"); <br />
foreach (Object obj in myList)<br />
{ Fichier.WriteLine(obj); } <br />
Fichier.Close();
i know that it take a big space in memory, but i try to optimize the traitement, what is the best for use ? string or object ??, thank you verry mutch.
|
|
|
|
|
If you are a programmer, you should know the difference between String and Object!
And if you don't know the difference, first get lessons or read a book.
Personal I think that you should read a book, because you ask all beginner questions.
First of all, you are probably still using an ArrayList, my suggestion: use List<type>.
Secondly, the difference between a String and Object.
Every String in C# is an Object, but not every Object is a String. Just as that all dogs are animals, but not every animal is a dog. Every type in C# is an Object, so int, String, Array, ArrayList, Double, Byte, those are Objects.
So which should you use, a String or an Object? Well you use a String if you know that the input value is a single or more characters (which will make for instance a sentence or word). If you don't know what the type will be (maybe it is a number, maybe a sentence), you use the Object type.
So you should use a String. Why? You know that the value from a textfile are words or at least characters, so you should store those values in a String.
Good luck!
And you should maybe try work on your English skill, but that's just a side note.
|
|
|
|
|
Dear All,
I have an application which reads an UDP packet sent by a device.
While reading, when the data sent has an value 0 then the byte stream which is read and in the application takes the value as "32" which means space.
I can't replace the byte with value 32 as 0 as in some case the space itself is coming in the stream..
For e.g if the value in byte are 65, 0 then the byte read by the application is 65 and 32.
Kindly help me to resolve the issue.
Thanks a lot in advance.
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
It sound like you are using something like a stream reader to decode the bytes into text? That would cause any unsupported character codes to change.
How are you doing the actual reading? Do you have any code to show?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Dear Friend,
Actually I am receiving the bytes as
serverSocket.EndReceive(ar, ref epSender);
Data streamRead = new Data(byteData);// byteData is to hold the read conents and Data is the class assigned as the object state for asyn reading.
Then I am taking bytes by bytes.
Actually now I am not having the complete code as I am not in office.
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
hi,
i am desigining a game in which i want that the image(that is a bitmap of simply looking like a pacman) to show the that it is eating the pills on the key press and i want to show the movement of its mouth when it eat pills.
|
|
|
|
|
And what is the question?
Maybe show some code (where it goes wrong).
|
|
|
|
|
the problem is i am not getting how to simulate or develop the motion in its mouth seems that it is eating the pills on the key press .
|
|
|
|
|
Well, this is not really something I've tried doing in C#. But I've done it in flash several times.
But to make it there, you should try and research about silverlight, it's about pictures and images and movement, it's like flash inside Visual Studio.
You could also use common sense. You want a picture to change several times per second, so it would look like motion. And this motion should only take place if you pressed the key.
First hook an event on your key press and then do something like this:
String[] imageList = { @"C:/Image1", @"C:/Image2", @"C:/Image3", @"C:/Image4", @"C:/Image5" };
public void keyPressed(Object sender, KeyEventArgs e)
{
for(int i = 0; i < imageList.Length; i++)
{
pictureBox.Image = new Image(imageList[i]);
Thread.Sleep(150);
}
}
What will this function do?
You first define a list of pictures (you can do this by adding them to the resources list, or just pointing to several files on your hard disk.
Then you loop through all the images and you add the images (from 1 to as many as you have in your imageList) and you let the application 'sleep' for 150 miliseconds.
This is a way to accomplish a motion.
In order to do this, you will have to do this inside a thread, because if you don't, your application won't be able to do anything while showing the motion.
|
|
|
|
|
thanxs alot for the suggestion i will try it and tell all about the results i have.
|
|
|
|
|
Hi all i have a problem that i have been struggling for a week and a half now
this is the function i use to try and update a image in my database
void t(MemoryStream msI)
{
string query;
query ="insert into testimage (id_image,pic) values(" +'"'+"t"+'"' + "," +"@pic)";
BinaryReader oReader = new BinaryReader(msI);
System.Data.Odbc.OdbcCommand cmd = new System.Data.Odbc.OdbcCommand(query,OdbcCon );
cmd.Parameters.Add("pic",oReader.ReadBytes((int)msI.Length));
cmd.Prepare();
cmd.ExecuteNonQuery();
MessageBox.Show("Image Added");
}
But the problem that i get that it doesn't insert any data into the blob field
msI is a Memory Stream that is the image that i want to insert
Any help would be greatly appreciated
|
|
|
|
|
hendrik wrote: +'"'+"t"+
Looks like a quote mismatch. I think this might be what you want,
query = "insert into testimage (id_image,pic) values('t', @pic)";
hendrik wrote: cmd.Parameters.Add("pic",oReader.ReadBytes((int)msI.Length));
Second paramter should be a valid OdbcType. You can use the OdbcType enum for it. Also, the parameter name should be @pic
Finally, assign the value of parameter and execute.
e.g.,
System.Data.Odbc.OdbcCommand command = new System.Data.Odbc.OdbcCommand(commandText, connection);<br />
command.Parameters.Add("@ID", SqlDbType.Int);<br />
command.Parameters["@ID"].Value = myvalue;
Edit - Forgot to mention the wrong parameter name
|
|
|
|
|
Thanks for the fead back i have implemented like you show still
no image gets saved to the blob field
void t(MemoryStream msI)
{
string query;
query ="insert into testimage (id_image,pic) values('t', @pic)";
BinaryReader oReader = new BinaryReader(msI);
System.Data.Odbc.OdbcCommand cmd = new System.Data.Odbc.OdbcCommand(query,OdbcCon );
cmd.Parameters.Add("@pic", System.Data.DbType.Byte);
cmd.Parameters["@pic"].Value = oReader.ReadBytes((int)msI.Length);
cmd.Prepare();
cmd.ExecuteNonQuery();
MessageBox.Show("Image Added");
}
Note That msI does have a image in it
Thanks any other ideas will help a lot
|
|
|
|
|
hendrik wrote: cmd.Parameters.Add("@pic", System.Data.DbType.Byte);
That says your trying to store a byte but your data is a byte array
Maybe you can use the ObdbType.Image datatype.
cmd.Parameters.Add("@pic", OdbcType.Image);
Also, MemoryStream can be directly converted to byte array.
byte[] blob = msI.ToArray()
|
|
|
|
|
Thanks have done that as well
no change to outcome
string query;
query ="insert into testimage (id_image,pic) values('t', @pic)";
msI.Position=0;
System.Data.Odbc.OdbcCommand cmd = new System.Data.Odbc.OdbcCommand(query,OdbcCon );
cmd.Parameters.Add("@pic",System.Data.Odbc.OdbcType.Image);
cmd.Parameters["@pic"].Value = msI.ToArray();
cmd.Prepare();
cmd.ExecuteNonQuery();
MessageBox.Show("Image Added");
thanks again for your help so far
Just for clarification i'm using Mysql as the DB
and sharpdeveloper for my IDE
And using MySQL ODBC 3.51 Driver for the odbc conention
modified on Saturday, February 14, 2009 12:43 PM
|
|
|
|
|
Hi,
maybe msI is a stream you just filled with some data and forgot to reposition to the beginning of the data?
try adding msI.Position=0;
Luc Pattyn [Forum Guidelines] [My Articles]
- 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 the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:05 AM
|
|
|
|
|
Hi,
why is your subject line starting with "MySQL" while your code uses ODBC?
the solution to your problem is in this page[^], read all of it!
PS: don't disable statements by commenting them out, it makes your source unreadable.
the purpose of comments is to clarify things, not obfuscate them.
Luc Pattyn [Forum Guidelines] [My Articles]
- 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 the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:06 AM
|
|
|
|
|
Thanks working great after replacing named parameter with a ?
and sorry for not putting every thing needed in the subject
line this was my first time posting on the forum
but i would like to as you one more question if you had 2 parameters
that you would wand to put in the same query how would go about doing that
and the commenting of code was done to show the implementation of the previous replays
|
|
|
|
|
hendrik wrote: Thanks
you're welcome.
hendrik wrote: if you had 2 parameters ...
then I would recommend you read this page[^] twice.
Luc Pattyn [Forum Guidelines] [My Articles]
- 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 the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Sunday, June 12, 2011 8:06 AM
|
|
|
|
|
Luc Pattyn wrote: then I would recommend you read this page[^] twice. Big Grin
thanks i don't know how i mist that the first time
|
|
|
|
|
Hello, I have a problem on the table layout panel control. I wanted to create a program that on run time I could set the table layout panel's number of rows and columns. My Problem is that the spaces of each boxes on the table are not evenly distributed. How do I make it evenly distributed?
|
|
|
|
|
This code worked fine for columns, it can also be slightly modifed to fit for rows:
tableLayoutPanel1.ColumnStyles.Clear();
int numOfColumns = 4;
tableLayoutPanel1.ColumnCount = numOfColumns;
for (int i = 0; i < numOfColumns ; i++ )
{
ColumnStyle cStyle = new ColumnStyle();
cStyle.SizeType = SizeType.Percent;
cStyle.Width = 100 / numOfColumns;
tableLayoutPanel1.ColumnStyles.Add(cStyle);
}
|
|
|
|
|
Is possible to define mp3 format in SDP protocol ?
In examples i found only definition for various voice comunication or asf/wma format.
|
|
|
|