C # operation of mysql database, sql statement runs normally in navicat, but executed in C #, no results

table of Contents

1. Problem description and cause

2. Solution (testing effective)


1. Problem description and cause

C # operates the mysql database, other queries are no problem, but it involves "select SYSTEM from companycode where CHP_NAME = @ CHP_NAME", and the CHP_NAME field is stored in Chinese . It runs normally in navicat, the result is correct
but it is executed in C # , Life and death have no results.

2. Solution (testing effective)

When connecting to the database, set the encoding Charset = utf8 to avoid this error

例如:string connectiontext = "Server=139.222.313.153;Database=testsys;User=root;Password=1123456;Charset=utf8;";

Published 30 original articles · Like1 · Visits1158

Guess you like

Origin blog.csdn.net/chunchunlaila/article/details/105197304