Beispiel #1
0
              /// <summary>
        /// 把datatable某行的值,生成insert的SQL语句
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="as_tablename"></param>
        /// <param name="ai_row"></param>
        /// <returns></returns>
        public static string of_InsertToTable(DataTable dt, string as_tablename, DataRow dr,out GysoftParameter[] ap_value)
        {
            ErrStr = "";
            if (dt == null)
            {
                ap_value = new GysoftParameter[1];
                return "";
            }

            ap_value = new GysoftParameter[dt.Columns.Count];

            n_create_sql lnv_sql = new n_create_sql();
            lnv_sql.of_SetTable(as_tablename);

            string ls_step = "1";
            string ls_rc="";
            try
            {
                ls_step = "2";

                for (int li_col = 0; li_col < dt.Columns.Count; li_col++)
                {
                    string ls_colName;
                    ls_colName = dt.Columns[li_col].ColumnName.ToString();
                    lnv_sql.of_AddCol(ls_colName, "@" + ls_colName);

                    ap_value[li_col] = new GysoftParameter();
                    ap_value[li_col].PaName = ls_colName;
                    ap_value[li_col].Value = dr[li_col].ToString();

                }
                ls_step = "3";
                ls_rc = lnv_sql.of_GetInsertSQL();
                ls_step = "4";
            }
            catch (Exception ex)
            {
                ErrStr =ls_step+"  "+ ex.ToString();
            }


            return ls_rc;

        }
Beispiel #2
0
        public static string of_InsertToTable(DataTable dt, string as_tablename, DataRow dr)
        {
            ErrStr = "";
            if (dt == null)
            {
                return "";
            }


            n_create_sql lnv_sql = new n_create_sql();
            lnv_sql.of_SetTable(as_tablename);

            string ls_step = "1";
            string ls_rc = "";
            try
            {
                ls_step = "2";

                for (int li_col = 0; li_col < dt.Columns.Count; li_col++)
                {
                    string ls_colName;
                    ls_colName = dt.Columns[li_col].ColumnName.ToString();

                    string ls_value;
                    ls_value = dr[li_col].ToString();
                    ls_value = ls_value.Replace("'", "''");
                    lnv_sql.of_AddCol(ls_colName, ls_value);
                }
                ls_step = "3";
                ls_rc = lnv_sql.of_GetInsertSQL();
                ls_step = "4";
            }
            catch (Exception ex)
            {
                ErrStr = ls_step + "  " + ex.ToString();
            }


            return ls_rc;

        }
Beispiel #3
0
        /// <summary>
        /// 把datatable某行的值,生成insert的SQL语句
        /// </summary>
        /// <param name="dt"></param>
        /// <param name="as_tablename"></param>
        /// <param name="ai_row"></param>
        /// <returns></returns>
        public static string of_InsertToTable(DataTable dt, string as_tablename, int ai_row, out GysoftParameter[] ap_value)
        {
            ErrStr = "";
            if (dt == null)
            {
                ap_value = new GysoftParameter[1];
                return "";
            }
            if (ai_row>=dt.Rows.Count)
            {
                ap_value = new GysoftParameter[1];
                return "";
            }

            ap_value = new GysoftParameter[dt.Columns.Count];
            n_create_sql lnv_sql = new n_create_sql();
            lnv_sql.of_SetTable(as_tablename);

            for (int li_col = 0; li_col < dt.Columns.Count; li_col++)
            {
                string ls_colName;
                ls_colName = dt.Columns[li_col].ColumnName.ToString();
                lnv_sql.of_AddCol(ls_colName, "@" + ls_colName);

                ap_value[li_col].PaName = ls_colName;
                ap_value[li_col].Value = dt.Rows[ai_row][li_col].ToString();
            }

            string ls_rc;
            ls_rc = lnv_sql.of_GetInsertSQL();

            return ls_rc;

        }