Q:

Passing Column name as string in mysql Insert query

this is what i am trying to do after receiving string from the serial port. i get whitespace between the data so i put two loops to eliminate them. i want to recieve data spanning multiple columns and a single row for every single run of do while loop.. Thanks in Advance
string text = sp.readline();

for (int i = 0; i < text.Length; )
 {
     p = text[i].ToString();
     if (p != " ")
     {
     do
        {
         x += text[i].ToString();
         s = text[i].ToString();
         i++;
         } while (s != " ");
         try
           {
              string col = "column" + no.ToString();
              MySqlCommand cmd = conn.CreateCommand();
              cmd.CommandText = "INSERT INTO testdata("+col+")VALUES(?data)";
              cmd.Parameters.Add("?data", MySqlDbType.VarChar).Value = x;
              cmd.ExecuteNonQuery();
              x = "";
              p = "";
              no++;
           }
         catch (Exception ex)
           {
              MessageBox.Show(ex.Message);
           }

     } i++;

}

A:

Sorry to say, you cannot, in any dialect of SQL, provide a table or column name as a bindable variable (or parameter). If it's working for MySQL that's terrific, but if you change over to any other DBMS make and model, it will suddenly stop working.
Also, INSERT means create a new row. You'll either need to insert all the column values at once in a single INSERT statement, or figure out how to INSERT one row and then UPDATE it for each new column value.  

