Q. string strSql = "INSERT INTO TBL_GYOMUTANGO "; strSql += "(WORD) "; strSql += "VALUES('" +strKey + "')"; -->strKey 是漢字時,程序顯示爲亂碼。 A. 使用Parameters解決亂碼 string strSql = "INSERT INTO TBL_GYOMUTANGO "; strSql += "(WORD, COMMENT) "; strSql += "VALUES(@strKey,@strComment)"; SqlCommand cmd = new SqlCommand(strSql,conn,trans); cmd.Parameters.Add(new SqlParameter("@strKey",SqlDbType.VarChar,50)); cmd.Parameters.Add(new SqlParameter("@strComment",SqlDbType.NVarChar ,200)); cmd.Parameters["@strKey"].Value = strKey; cmd.Parameters["@strComment"].Value = strComment; //SqlCommand cmd = new SqlCommand(strSql,conn); cmd.CommandType = CommandType.Text; iRet = cmd.ExecuteNonQuery(); |
041006 A DB 亂碼
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.