Problem to query

Hi,
It seems running this
 
               string sql2 = @"insert into err(ln) values('" + sql + "')";
                dt = DBUtil.runSQL(sql2);
				...
        public static DataTable runSQL_Macau(string sql)
        {
            DataTable dt = new DataTable();
            MySqlConnection conn = DBUtil.GetConnectionMySql(DB_CONN_MACAU);

            if (!string.IsNullOrEmpty(sql))
            {
                try
                {
                    dt = DBUtil.ExecuteDataTable(conn, sql);

                }
                catch (Exception e)
                {
                    logger(sql);
                    logger(e.ToString());
                }
            }

            DBUtil.Close(conn);
            return dt;
        }
		...

Open in new window


it would not insert the record. how to adjust the above?
LVL 12
HuaMin ChenProblem resolverAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
any error message? what happen if you trace/debug it? is your connection valid?
HuaMin ChenProblem resolverAuthor Commented:
Hi,
I try to put these
                try
                {
                    string sql2 = @"insert into err(ln) values('" + sql + "')";
                    dt = DBUtil.runSQL(sql2);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("iii" + ex.StackTrace); Console.ReadKey();
                }

Open in new window

but I get nothing shown, while other message right before the above part, can be shown.
HuaMin ChenProblem resolverAuthor Commented:
Any help?
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

HuaMin ChenProblem resolverAuthor Commented:
Hi,
I adjust the codes and now have got this Stacktrace
   於 MySql.Data.MySqlClient.MySqlStream.ReadPacket()
   於 MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& i
nsertedId)
   於 MySql.Data.MySqlClient.Driver.GetResult(Int32 statementId, Int32& affected
Rows, Int64& insertedId)
   於 MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
 
   於 MySql.Data.MySqlClient.MySqlDataReader.NextResult()
   於 MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior
)
   於 MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
   於 Utility.DBUtil.ExecuteNonQuery(MySqlConnection conn, MySqlTransaction tran
, String query) 於 C:\source\New_Test\DBUtil.cs: 行 172
   於 Test.Program.ProcessSmsDlv_VG(DateTime current_time) 於C:\source
\New_Test\Program.cs: 行 439
 

Open in new window

what to correct, while line 439 is shown below
             
   try
437                {
438                    string sql2 = @"insert into err(ln) values('" + sql + "')";
439                    DBUtil.ExecuteNonQuery(conn, trans, sql2);
                }
 

Open in new window

Éric MoreauSenior .Net ConsultantCommented:
what happen if you try to run your query in MySQL?
HuaMin ChenProblem resolverAuthor Commented:
I am not able to get value of "sql" so I cannot directly run the script on Mysql.
Éric MoreauSenior .Net ConsultantCommented:
very odd. you need that to go further!
HuaMin ChenProblem resolverAuthor Commented:
Here is the error
 
You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near '%m-%d %H:%i:%s') as in_ti
me_dscr,  date_format(p.stockout_time,'%Y-%m-%d %H:%i:%' at line 1
 

Open in new window

got within VS, while this is the script
 
                sql = @"select " +
                    " null as row_num, " +
                    " date_format(p.in_time,'%Y-%m-%d %H:%i:%s') as in_time_dscr, " +
                    " date_format(p.stockout_time,'%Y-%m-%d %H:%i:%s') as stockout_time_dscr, " +
                    " date_format(ADDDATE(p.store_rcv_time, " + package_expiry_day_vg.ToString() + "), '%c月%e日') as expiry_date_chi, " +
                    " date_format(ADDDATE(p.store_rcv_time, " + package_expiry_day_vg.ToString() + "), '%D %b') as expiry_date_eng, " +
                    " c_s.sms_addr_eng, " +
                    " c_s.sms_addr_chi, " +
                    " c_s.store_no, " +
                    " p.*  " +
                    " from package_vg p  " +
                    " left join c_store_vg c_s on c_s.dscr = p.store_dscr " +
                    " where p.deleted = '0' " +
                    " and (p.phone like '9%' or p.phone like '6%' or p.phone like '5%') " +
                    " and length(trim(p.phone)) = 8 " +
                    " and c_s.send_sms = 1 " +
                    " and (p.status = 'store_rcv' or p.status = 'store_app_rtn') " +
                    " and p.sms_send = 0 " +
                    " and date_format(p.store_rcv_time,'%Y-%m-%d') >= " + DBUtil.GetSqlString(From_Date.ToString(DBUtil.DATE_FORMAT)) + " " +
                    " and date_format(p.store_rcv_time,'%Y-%m-%d') < " + DBUtil.GetSqlString(To_Date.ToString(DBUtil.DATETIME_FORMAT)) + " " +
                    " order by p.id";
					

Open in new window

why does the error come out?
Éric MoreauSenior .Net ConsultantCommented:
Your error message is clear. The date is not provided in the expected format

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HuaMin ChenProblem resolverAuthor Commented:
Really I do not know which line is leading to the problem shown.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.