Please review this.
public int InsertQuery(string Query)
{
int LastInsertedID = -1;
MySqlCommand MySqlCmd = new MySqlCommand(Query, this.sqlConn);
try
{
MySqlCmd.ExecuteNonQuery();
LastInsertedID = int.Parse(MySqlCmd.LastInsertedId.ToString());
}
catch (Exception excp)
{
Exception myExcp = new Exception("Could not execute INSERT Query.<br />" + Query + "<br /> Error: <br />" + excp.Message, excp);
throw (myExcp);
}
return LastInsertedID;
}
public int AddChannel(NameValueCollection FormValues)
{
string Keys = string.Join(",",FormValues.AllKeys);
string Values = string.Join(",", FormValues.AllKeys.Select(key => String.Format("\"{0}\"", HttpContext.Current.Server.HtmlEncode(FormValues[key]))));
return InsertQuery("INSERT INTO channels (" + Keys + ") VALUES (" + Values + ");");
}