internal static SqlCommand CreateCommand(MapFeature mapFeature, Kml2SqlConfig config) { var query = CreateCommandQuery(mapFeature, config); SqlCommand sqlCommand = new SqlCommand(query); sqlCommand.Parameters.AddWithValue("@Id", mapFeature.Id); sqlCommand.Parameters.AddWithValue("@Name", GetNameParam(mapFeature)); foreach (KeyValuePair <string, string> simpleData in mapFeature.Data) { sqlCommand.Parameters.AddWithValue("@" + config.GetColumnName(simpleData.Key), simpleData.Value); } return(sqlCommand); }
internal static string CreateCommandQuery( MapFeature mapFeature, Kml2SqlConfig config, bool useParameters = true, bool declareVariables = true) { var columnNames = mapFeature.Data.Keys.Select(x => config.GetColumnName(x)).ToArray(); string columnText = GetColumnText(columnNames); string parameters = GetParameters(mapFeature, useParameters, columnNames); StringBuilder query = new StringBuilder(); query.Append(ParseCoordinates(mapFeature, config, declareVariables)); query.Append(string.Format($"INSERT INTO {config.TableName}({config.IdColumnName}, {config.NameColumnName}, {columnText} {config.PlacemarkColumnName})")); query.Append(Environment.NewLine); query.Append($"VALUES({parameters} @placemark);"); return(query.ToString()); }