Click here to Skip to main content
15,867,686 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to transfer data between two form Pin
BillWoodruff12-May-12 16:48
professionalBillWoodruff12-May-12 16:48 
GeneralRe: How to transfer data between two form Pin
Promance12-May-12 19:38
Promance12-May-12 19:38 
GeneralRe: How to transfer data between two form Pin
BillWoodruff15-May-12 16:14
professionalBillWoodruff15-May-12 16:14 
GeneralRe: How to transfer data between two form Pin
Promance19-May-12 3:47
Promance19-May-12 3:47 
AnswerRe: How to transfer data between two form Pin
Apocalypse Now13-May-12 15:00
Apocalypse Now13-May-12 15:00 
GeneralRe: How to transfer data between two form Pin
Dave Kreskowiak14-May-12 2:15
mveDave Kreskowiak14-May-12 2:15 
GeneralRe: How to transfer data between two form Pin
Pete O'Hanlon14-May-12 2:56
subeditorPete O'Hanlon14-May-12 2:56 
QuestionCreate an object with a string. Pin
coolfetus11-May-12 17:44
coolfetus11-May-12 17:44 
I am converting from PHP to C# and I might be doing this completely wrong but here goes. I am reading rows from a database with a reader. Then using a foreach command I am walking through the records creating an object and then adding the object to a List<t>. I then return the list to be used for other purposes. But since the object that I am adding to the List is sent by reference it ends up filling the list with the values of the last object added. I am looking for advice on alternate was to fill the List or alternate ways to use the objects. Please try to refrain from just telling me I am and idiot. Be assured I am already aware of this fact.Smile | :) Thanks to anyone that can offer advice. Below is some of the code. I hope that I posted it OK.

Mark

public object find_by_sql(string sql_statement, Type object_type, database working_database)
            {
            //Using the supplied sql statement query the database and return a reader object.
            working_database.reader = (SqlDataReader)working_database.query(sql_statement);
            //Instantiate a object determined by the calling class using the argument object_type
            object defined_object = Activator.CreateInstance(object_type);
            //Tnstantiate an Array of objects to return.
            List<object> object_array = new List<object>();
            //Step through the returned data rows from the sql statement
            while (working_database.reader.Read())
                {
                Console.WriteLine("Calling Instantiation");
                object_array.Add(instantiate(working_database.reader, defined_object));
                Console.WriteLine("object test = " + defined_object.GetType().GetField("descr").GetValue(defined_object).ToString());
                Console.WriteLine("Returned from Instantiation");
                }
            return (object_array);
            }

        private static object instantiate(SqlDataReader records,object defined_object)
            {
            for (int i = 0; i < (records.FieldCount); i++)
                {
                int one = (int)records.GetInt32(0);
                string two = (string)records.GetName(i);
                var three = records[i];
                //record_values.Add(two, three);
                Console.WriteLine("{0} : {1} - {2}", one, two, three);
                defined_object.GetType().GetField(two).SetValue(defined_object, three);
                //Console.WriteLine("{0}, {1}", working_database.reader.GetInt32(0), String.Format("{0}", working_database.reader[4]));
                //return_value = instantiate(working_database.reader);
                }
            return(defined_object);
            }

AnswerRe: Create an object with a string. Pin
Luc Pattyn11-May-12 18:23
sitebuilderLuc Pattyn11-May-12 18:23 
Questionc# tutorial Pin
Shubham Vijay11-May-12 8:41
Shubham Vijay11-May-12 8:41 
AnswerRe: c# tutorial Pin
Ravi Bhavnani11-May-12 9:04
professionalRavi Bhavnani11-May-12 9:04 
QuestionDisplaying XHTML elements with namespaces in .NET WebBrowser control Pin
Orjan Westin11-May-12 5:08
professionalOrjan Westin11-May-12 5:08 
QuestionParent child relation through the designer Pin
Ronny Portier11-May-12 4:20
Ronny Portier11-May-12 4:20 
AnswerRe: Parent child relation through the designer Pin
Dave Kreskowiak11-May-12 7:25
mveDave Kreskowiak11-May-12 7:25 
AnswerRe: Parent child relation through the designer Pin
BillWoodruff12-May-12 16:54
professionalBillWoodruff12-May-12 16:54 
QuestionPicturebox and Progressbar question Pin
Hagen McCarthy11-May-12 4:13
Hagen McCarthy11-May-12 4:13 
AnswerRe: Picturebox and Progressbar question Pin
Sentenryu11-May-12 4:32
Sentenryu11-May-12 4:32 
GeneralRe: Picturebox and Progressbar question Pin
Hagen McCarthy11-May-12 4:39
Hagen McCarthy11-May-12 4:39 
GeneralRe: Picturebox and Progressbar question Pin
Sentenryu11-May-12 5:06
Sentenryu11-May-12 5:06 
GeneralRe: Picturebox and Progressbar question Pin
Hagen McCarthy11-May-12 5:10
Hagen McCarthy11-May-12 5:10 
GeneralRe: Picturebox and Progressbar question Pin
Hagen McCarthy11-May-12 5:21
Hagen McCarthy11-May-12 5:21 
GeneralRe: Picturebox and Progressbar question Pin
Hagen McCarthy11-May-12 4:59
Hagen McCarthy11-May-12 4:59 
AnswerRe: Picturebox and Progressbar question Pin
BobJanova11-May-12 6:37
BobJanova11-May-12 6:37 
GeneralRe: Picturebox and Progressbar question Pin
Hagen McCarthy11-May-12 7:37
Hagen McCarthy11-May-12 7:37 
AnswerRe: Picturebox and Progressbar question Pin
Alan N11-May-12 7:28
Alan N11-May-12 7:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.