Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Kulwant Singh
  Where is Kulwant Singh?
 Shimla
 India
 Kulwant Singh
 Tags
Subject: variable no. of parameters
Thread ID: 393821 Message ID: 393821 # Views: 49 # Ratings: 0
Version: Not Applicable Category: .NET
Date: Tuesday, December 24, 2013 7:43:45 AM         
   


Dear Experts,

as you can see, this is C# code for inserting Data...

        public void insertData(string name,string surName, string age)
        {
            SqlConnection connection = new SqlConnection(getConnectionString());
            SqlCommand cmd = new SqlCommand("INSERT INTO MYTABLE (NAME,SURNAME,AGE) VALUES (@NAME,@SURNAME,@AGE)", connection);
            try
            {
                cmd.Parameters.AddWithValue("@NAME", name.ToUpper());
                cmd.Parameters.AddWithValue("@SURNAME", surName.ToUpper());
                cmd.Parameters.AddWithValue("@AGE", age.ToUpper());
                connection.Open();
                cmd.ExecuteNonQuery();
                connection.Close();
                connection.Dispose();
            }


This method accepts 3 parameters and the TRY block adds 3 parameters in three lines of code.

How do I re-write this code to send in N number of parameters ie if I need to deal with 5 fields, I send in five parameters and the try block add 5 Parameters...

PLUS
instead of a Hard coded SQL Command, if I send in another parameter ie the SQL COMMAND
how to write code for this line
SqlCommand cmd = new SqlCommand(.....????


TIA



kulwant
(Help Save the TIGER. Save Wildlife. Live & let Live)

ENTIRE THREAD

variable no. of parameters Posted by Kulwant Singh @ 12/24/2013 7:43:45 AM
RE: variable no. of parameters Posted by Stefan Wuebbe @ 12/24/2013 11:00:04 AM
RE: variable no. of parameters Posted by Cetin Basoz @ 12/24/2013 2:31:56 PM