Esempio n. 1
0
        private void AddColumnNode(TreeNode treeNode, Column column)
        {
            TreeNode node;

            node = new TreeNode(column.PropertyName);
            node.Tag = TreeNodeTypes.Column;

            treeNode.Nodes.Add(node);
        }
Esempio n. 2
0
 /// <summary>
 /// Matches a SQL Server data type to a SqlClient.SqlDbType.
 /// </summary>
 /// <param name="column">Object that stores the information for the column the parameter represents.</param>
 /// <returns>A string representing a SqlClient.SqlDbType.</returns>
 public static string GetSqlDBType(Column column)
 {
     switch (column.DbType.ToLower())
     {
         case "binary":
             return "Binary";
         case "bigint":
             return "Int64";
         case "bit":
             return "Boolean";
         case "char":
             return "String";
         case "datetime":
             return "DateTime";
         case "decimal":
             return "Decimal";
         case "float":
             return "Double";
         case "image":
             return "Binary";
         case "int":
             return "Int32";
         case "money":
             return "Currency";
         case "nchar":
             return "String";
         case "ntext":
             return "String";
         case "nvarchar":
             return "String";
         case "numeric":
             return "Decimal";
         case "real":
             return "Single";
         case "smalldatetime":
             return "DateTime";
         case "smallint":
             return "Int16";
         case "smallmoney":
             return "Currency";
         case "sql_variant":
             return "Object";
         case "sysname":
             return "String";
         case "text":
             return "String";
         case "timestamp":
             return "DateTime";
         case "tinyint":
             return "Byte";
         case "varbinary":
             return "Binary";
         case "varchar":
             return "String";
         case "uniqueidentifier":
             return "Guid";
         case "xml":
             return "String";
         default: // Unknow data type
             throw (new Exception("Invalid SQL Server data type specified: " + column.DbType));
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Creates a string for a SqlParameter representing the specified column.
        /// </summary>
        /// <param name="column">Object that stores the information for the column the parameter represents.</param>
        /// <returns>String containing SqlParameter information of the specified column for a method call.</returns>
        public static string CreateSqlParameter(Column column)
        {
            string[] methodParameter;
            string columnDBType = GetSqlDBType(column);

            // Get an array of data types and variable names
            methodParameter = CreateMethodParameter(column).Split(' ');

            return "myCommand.AddInParameter(\"@" + column.PropertyName + "\", DbType." + columnDBType + ", " + methodParameter[1] + ")";
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a string for a method parameter representing the specified column.
        /// </summary>
        /// <param name="column">Object that stores the information for the column the parameter represents.</param>
        /// <returns>String containing parameter information of the specified column for a method call.</returns>
        public static string CreateMethodParameter(Column column)
        {
            string parameter;
            string columnName;

            // Format the column name
            columnName = column.PropertyName;
            columnName = FormatCamel(columnName);

            switch (column.DbType.ToLower())
            {
                case "binary":
                    parameter = "byte[] " + columnName;
                    break;
                case "bigint":
                    parameter = "Int64 " + columnName;
                    break;
                case "bit":
                    parameter = "bool " + columnName;
                    break;
                case "char":
                    parameter = "string " + columnName;
                    break;
                case "datetime":
                    parameter = "DateTime " + columnName;
                    break;
                case "decimal":
                    parameter = "decimal " + columnName;
                    break;
                case "float":
                    parameter = "double " + columnName;
                    break;
                case "image":
                    parameter = "byte[] " + columnName;
                    break;
                case "int":
                    parameter = "int " + columnName;
                    break;
                case "money":
                    parameter = "decimal " + columnName;
                    break;
                case "nchar":
                    parameter = "string " + columnName;
                    break;
                case "ntext":
                    parameter = "string " + columnName;
                    break;
                case "nvarchar":
                    parameter = "string " + columnName;
                    break;
                case "numeric":
                    parameter = "decimal " + columnName;
                    break;
                case "real":
                    parameter = "float " + columnName;
                    break;
                case "smalldatetime":
                    parameter = "DateTime " + columnName;
                    break;
                case "smallint":
                    parameter = "short " + columnName;
                    break;
                case "smallmoney":
                    parameter = "decimal " + columnName;
                    break;
                case "sql_variant":
                    parameter = "object " + columnName;
                    break;
                case "sysname":
                    parameter = "string " + columnName;
                    break;
                case "text":
                    parameter = "string " + columnName;
                    break;
                case "timestamp":
                    parameter = "DateTime " + columnName;
                    break;
                case "tinyint":
                    parameter = "byte " + columnName;
                    break;
                case "varbinary":
                    parameter = "byte[] " + columnName;
                    break;
                case "varchar":
                    parameter = "string " + columnName;
                    break;
                case "uniqueidentifier":
                    parameter = "Guid " + columnName;
                    break;
                case "xml":
                    parameter = "String " + columnName;
                    break;
                default: // Unknow data type
                    throw (new Exception("Invalid SQL Server data type specified: " + column.DbType));
            }

            // Return the new parameter string
            return parameter;
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a string containing the parameter declaration for a stored procedure based on the parameters passed in.
        /// </summary>
        /// <param name="column">Object that stores the information for the column the parameter represents.</param>
        /// <returns>String containing parameter information of the specified column for a stored procedure.</returns>
        public static string CreateParameterString(Column column)
        {
            string columnName;
            string parameter;

            columnName = column.PropertyName;

            switch (column.DbType.ToLower()) {
                case "binary":
                    parameter = "@" + columnName + " " + column.DbType + "(" + column.Length + ")";
                    break;
                case "bigint":
                    parameter = "@" + columnName + " " + column.DbType;
                    break;
                case "bit":
                    parameter = "@" + columnName + " " + column.DbType;
                    break;
                case "char":
                    parameter = "@" + columnName + " " + column.DbType + "(" + column.Length + ")";
                    break;
                case "datetime":
                    parameter = "@" + columnName + " " + column.DbType;
                    break;
                case "decimal":
                    if (column.Scale.Length == 0)
                        parameter = "@" + columnName + " " + column.DbType + "(" + column.Precision + ")";
                    else
                        parameter = "@" + columnName + " " + column.DbType + "(" + column.Precision + ", " + column.Scale + ")";
                    break;
                case "float":
                    parameter = "@" + columnName + " " + column.DbType + "(" + column.Precision + ")";
                    break;
                case "image":
                    parameter = "@" + columnName + " " + column.DbType;
                    break;
                case "int":
                    parameter = "@" + columnName + " " + column.DbType;
                    break;
                case "money":
                    parameter = "@" + columnName + " " + column.DbType;
                    break;
                case "nchar":
                    parameter = "@" + columnName + " " + column.DbType + "(" + column.Length + ")";
                    break;
                case "ntext":
                    parameter = "@" + columnName + " " + column.DbType;
                    break;
                case "nvarchar":
                    parameter = "@" + columnName + " " + column.DbType + "(" + column.Length + ")";
                    break;
                case "numeric":
                    if (column.Scale.Length == 0)
                        parameter = "@" + columnName + " " + column.DbType + "(" + column.Precision + ")";
                    else
                        parameter = "@" + columnName + " " + column.DbType + "(" + column.Precision + ", " + column.Scale + ")";
                    break;
                case "real":
                    parameter = "@" + columnName + " " + column.DbType;
                    break;
                case "smalldatetime":
                    parameter = "@" + columnName + " " + column.DbType;
                    break;
                case "smallint":
                    parameter = "@" + columnName + " " + column.DbType;
                    break;
                case "smallmoney":
                    parameter = "@" + columnName + " " + column.DbType;
                    break;
                case "sql_variant":
                    parameter = "@" + columnName + " " + column.DbType;
                    break;
                case "sysname":
                    parameter = "@" + columnName + " " + column.DbType;
                    break;
                case "text":
                    parameter = "@" + columnName + " " + column.DbType;
                    break;
                case "timestamp":
                    parameter = "@" + columnName + " " + column.DbType;
                    break;
                case "tinyint":
                    parameter = "@" + columnName + " " + column.DbType;
                    break;
                case "varbinary":
                    parameter = "@" + columnName + " " + column.DbType + "(" + column.Length + ")";
                    break;
                case "varchar":
                    parameter = "@" + columnName + " " + column.DbType + "(" + column.Length + ")";
                    break;
                case "uniqueidentifier":
                    parameter = "@" + columnName + " " + column.DbType;
                    break;
                case "xml":
                    parameter = "@" + columnName + " " + column.DbType;
                    break;
                default: // Unknow data type
                    throw (new Exception("Invalid SQL Server data type specified: " + column.DbType));
            }

            // Return the new parameter string
            return parameter;
        }