I am working on a class that will allow me to insert data into any mysql table that I pass into the class. For the most part I have everything done except for adding parameters to the sql query.
What I have done is pass an ArrayList of column names/ column types into my method, and then I take this data and parse it out and build my query from there. The one issue I have is, when adding parameters to the query, I am unable to figure out how to take the data I passed in and use it in conjunction with MySqlDbType.
Here is a short snippet
cmd.Parameters. Add(fldName, MySqlDbType.Var Char); // static way to add
Here is my current code base. Just as a short fyi, the array list is a multidimensiona l arraylist. I know the code below is wrong, just now sure how to use the string fldType as a member of MySqlDbType.
What I have done is pass an ArrayList of column names/ column types into my method, and then I take this data and parse it out and build my query from there. The one issue I have is, when adding parameters to the query, I am unable to figure out how to take the data I passed in and use it in conjunction with MySqlDbType.
Here is a short snippet
cmd.Parameters. Add(fldName, MySqlDbType.Var Char); // static way to add
Here is my current code base. Just as a short fyi, the array list is a multidimensiona l arraylist. I know the code below is wrong, just now sure how to use the string fldType as a member of MySqlDbType.
Code:
for (int i = 0; i < (fldCol[0] as ArrayList).Count; i++) { string fldName = "@" + (fldCol[0] as ArrayList)[i].ToString(); string fldType = (fldCol[1] as ArrayList)[i].ToString(); fldType = fldType .Replace("(", ""); fldType = fldType .Replace(")", ""); cmd.Parameters.Add(fldName, MySqlDbType[fldType]); cmd.Parameters[fldName].Value = dataCol[i]; }
Comment