DB中的乱码==>修正

SQL数据处理与编码转换
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; using System.Text.RegularExpressions; using System.Data.SqlClient; using System.Data; namespace ConsoleApplication2 { class Program { static string connectionString = "server=192.168.148.80;uid=ecuser;pwd=1234;database=ec15_20120117_liu;pooling=true; Min Pool Size=5; Max Pool Size=100"; static void Main(string[] args) { string sql = "SELECT PatientID,ForeignName,ForeignName_New FROM Patient_YNG ORDER BY PatientID"; SqlConnection con = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand(sql, con); SqlDataAdapter adapter =new SqlDataAdapter(cmd); DataTable dt=new DataTable(); adapter.Fill(dt); adapter.UpdateCommand=new SqlCommandBuilder(adapter).GetUpdateCommand(); foreach (DataRow dr in dt.Rows) { dr["ForeignName_New"]=ISO8859_GB2312(dr["ForeignName"].ToString()); } adapter.Update(dt); con.Close(); Console.ReadLine(); } //读出时进行转换 static string ISO8859_GB2312(string read) { //声明字符集 System.Text.Encoding iso8859, gb2312; string[] enArr = { "iso8859-1", "gb2312", "utf-8", "big5", }; //iso8859 iso8859 = System.Text.Encoding.GetEncoding(enArr[0]); //国标2312 //gb2312 = System.Text.Encoding.GetEncoding(enArr[2]); byte[] iso; iso = iso8859.GetBytes(read); //返回转换后的字符 string s = new String(System.Text.Encoding.Default.GetChars(iso)); //s = System.Text.Encoding.UTF8.GetString(read); return s; //return gb2312.GetString(iso); } } } INSERT INTO Patient_YNG (PatientID,ForeignName) SELECT PatientID, ForeignName FROM Patient WHERE clinicid = 1483 AND ForeignName IS NOT NULL AND LEN(ForeignName) != 0 ORDER BY PatientID UPDATE patient_yng SET PatientFirstName= (SELECT PatientFirstName FROM patient WHERE patient.PatientID=patient_yng.PatientID ) ,PatientlastName= (SELECT PatientlastName FROM patient WHERE patient.PatientID=patient_yng.PatientID ) SELECT * FROM patient_yng --修正后的还有的乱码判断 SELECT * FROM Patient_YNG WHERE ForeignName_New LIKE '%?%' or ForeignName_New LIKE '%#%' OR ForeignName_New LIKE '%''%' OR ForeignName_New LIKE '%"%' OR ForeignName_New LIKE '%&%' OR ForeignName_New LIKE '%a%' OR ForeignName_New LIKE '%b%' OR ForeignName_New LIKE '%c%' OR ForeignName_New LIKE '%d%' OR ForeignName_New LIKE '%e%' OR ForeignName_New LIKE '%f%' OR ForeignName_New LIKE '%g%' OR ForeignName_New LIKE '%h%' OR ForeignName_New LIKE '%i%' OR ForeignName_New LIKE '%j%' OR ForeignName_New LIKE '%k%' OR ForeignName_New LIKE '%l%' OR ForeignName_New LIKE '%m%' OR ForeignName_New LIKE '%n%' OR ForeignName_New LIKE '%o%' OR ForeignName_New LIKE '%p%' OR ForeignName_New LIKE '%q%' OR ForeignName_New LIKE '%r%' OR ForeignName_New LIKE '%s%' OR ForeignName_New LIKE '%t%' OR ForeignName_New LIKE '%u%' OR ForeignName_New LIKE '%v%' OR ForeignName_New LIKE '%w%' OR ForeignName_New LIKE '%x%' OR ForeignName_New LIKE '%y%' OR ForeignName_New LIKE '%z%'

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>欢迎来到我的御书房</title> <style> .style1{ font-family: "Times New Roman", Times, serif; font-size: 16px; line-height: 1.6; color: #333; } a { text-decoration: none; } table { width: 1000px; border-collapse: collapse; background: linear-gradient(to right, #e0eafc, #cfdef3); } th, td { border: 1px solid #ddd; padding: 8px; text-align: left; border: 1px solid #ddd; padding: 5px; } th { background-color: #f2f2f2; text-align: center; } th:hover { color: #0056b3; /* 鼠标悬停时颜色稍变深 */ } tr:nth-child(odd) { background-color: #f2f2f2; } </style> </head> <?php include("conn.php"); ?> <body> <div id="apDiv1" align="center"><img src="lili3277.jpg" width="796" height="108" /></div> <div id="apDiv2"> <table width="867" border="0" align="center" > <tr> <th width="105"><span class="style1"><?PHP echo date("Y-m-d"); ?></span></th> <th width="114"><span class="style1"><a href="index.php">首页</a></span></th> <th width="125"><span class="style1"><a href="borrow.php">浏览信息</a></span></th> <th width="116"><span class="style1"><a href="add.php">添加图书</a></span></th> <th width="102"><span class="style1"><a href="search.php">简单查询</a></span></th> <th width="93"><span class="style1"><a href="searchmore.php">复杂查询</a></span></th> <th width="90"><span class="style1"><a href="group.php">分组统计</a></span></th> <th width="88"><span class="style1"><a href="quit.php">退出系统</a></span></th> </tr> </table> </div> <div id="apDiv3"> <form id="forml" name="forml" action="" method="post"> <table width="778" border="1" align="center"> <tr> <th width="97"><a href=" ?od=id" class="style1">图书编号</a></th> <th width="93"><a href=" ?od=bookname" class="style1">图书名称</a></th> <th width="95"><a href=" ?od=issuDate" class="style1">出版日期</a></th> <th width="93"><a href=" ?od=price" class="style1">图书定价</a></th> <th width="57"><a href=" ?od=maker" class="style1">作者</a></th> <th width="76"><a href=" ?od=publisher" class="style1">出版社</a></th> <th width="92"><span class="style1">操作</span></th> </tr> <?php $od=$_GET[od]; if($od==""){ $sql="select * from tb_book order by id desc limit 12";}else{ $sql="select * from tb_book order by ".$od." desc limit 12"; } $result=mysqli_query($conn,$sql); while($myrow=mysqli_fetch_array($result)){ ?> <tr> <td><div align="center"><span class="style1"><?php echo $myrow[0]; ?></span></div></td> <td><div align="center"><span class="style1"><?php echo $myrow[1]; ?></span></div></td> <td><div align="center"><span class="style1"><?php echo $myrow[2]; ?></span></div></td> <td><div align="center"><span class="style1"><?php echo $myrow[3]; ?></span></div></td> <td><div align="center"><span class="style1"><?php echo $myrow[4]; ?></span></div></td> <td><div align="center"><span class="style1"><?php echo $myrow[5]; ?></span></div></td> <td><div align="center"><span class="style1"><a href="del.php?id=<? echo $myrow[0]?>">删除</a>/<a href="update.php?id=<? echo $myrow[0]?>">修改</a></span></div></td> </tr> <?php }?> </table> </form> </div> <div id="apDiv4"> <p align="center">版权所有:22电子商务专业</p> <p align="center">校址:安徽省池州市教育园区</p> </div> </body> </html> 这个代码显示出的图书名称等信息是乱码,帮我分析一下什么问题, <?php $conn = mysqli_connect("localhost", "root", "root", "db_database18") or die("连接数据库服务器失败!".mysqli_connect_error()); mysqli_query($conn,"set name utf8"); ?> 上面这个是数据库连接文件,图书信息在数据库里可以正常显示
06-07
PS C:\Users\Administrator> <# >> .SYNOPSIS >> Initialize development environment and create project structure >> .DESCRIPTION >> Create standardized project directory structure with basic files >> #> >> >> function Initialize-Project { >> param( >> [Parameter(Mandatory=$true)] >> [string]$ProjectName, >> >> [ValidateSet("web", "python", "node", "dotnet")] >> [string]$ProjectType = "web", >> >> [string]$RootPath = "E:\ProjectEcosystem\ProjectMonitor" >> ) >> >> # 设置控制台编码为UTF-8防止乱码 >> [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 >> $OutputEncoding = [System.Text.Encoding]::UTF8 >> >> # 创建项目根目录 >> $projectDir = Join-Path -Path $RootPath -ChildPath $ProjectName >> New-Item -Path $projectDir -ItemType Directory -Force | Out-Null >> Set-Location $projectDir >> >> # 创建基础目录结构 >> $dirs = @('src', 'docs', 'tests', 'config', 'logs') >> $dirs | ForEach-Object { >> New-Item -Path $_ -ItemType Directory -Force | Out-Null >> } >> >> # 创建项目类型特定的文件 >> switch ($ProjectType.ToLower()) { >> "web" { >> # HTML基础文件 >> Set-Content -Path 'src\index.html' -Value @' >> <!DOCTYPE html> >> <html lang="zh-CN"> >> <head> >> <meta charset="UTF-8"> >> <title>$ProjectName</title> >> <link rel="stylesheet" href="style.css"> >> </head> >> <body> >> <h1>欢迎来到 $ProjectName</h1> >> <script src="main.js"></script> >> </body> >> </html> >> '@ >> # CSS文件 >> Set-Content -Path 'src\style.css' -Value @' >> body { >> font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; >> margin: 0; >> padding: 20px; >> background-color: #f5f5f5; >> } >> '@ >> # JavaScript文件 >> Set-Content -Path 'src\main.js' -Value @' >> console.log("$ProjectName 已启动"); >> document.addEventListener('DOMContentLoaded', () => { >> console.log("DOM 加载完成"); >> }); >> '@ >> } >> "python" { >> # Python主文件 >> Set-Content -Path 'src\main.py' -Value @' >> import logging >> >> logging.basicConfig(level=logging.INFO, >> format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', >> filename='../logs/app.log') >> >> def main(): >> print("项目 $ProjectName 已启动") >> logging.info("应用程序启动") >> >> if __name__ == "__main__": >> main() >> '@ >> # 需求文件 >> Set-Content -Path 'requirements.txt' -Value '# 项目依赖' >> } >> "node" { >> # Node.js入口文件 >> Set-Content -Path 'src\index.js' -Value @' >> const express = require('express'); >> const app = express(); >> const port = 3000; >> >> app.get('/', (req, res) => { >> res.send('欢迎来到 $ProjectName'); >> }); >> >> app.listen(port, () => { >> console.log(`服务器运行在 http://localhost:${port}`); >> }); >> '@ >> # package.json >> Set-Content -Path 'package.json' -Value @' >> { >> "name": "$ProjectName", >> "version": "1.0.0", >> "description": "", >> "main": "src/index.js", >> "scripts": { >> "start": "node src/index.js", >> "test": "echo \"Error: no test specified\" && exit 1" >> }, >> "keywords": [], >> "author": "", >> "license": "ISC", >> "dependencies": { >> "express": "^4.18.2" >> } >> } >> '@ >> } >> "dotnet" { >> # 生成随机GUID >> $guid = [Guid]::NewGuid().ToString().ToUpper() >> >> # .NET解决方案文件 >> Set-Content -Path "$ProjectName.sln" -Value @" >> Microsoft Visual Studio Solution File, Format Version 12.00 >> # Visual Studio Version 17 >> Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "$ProjectName", "src\$ProjectName\$ProjectName.csproj", "{$guid}" >> EndProject >> "@ >> # 创建项目目录 >> $projectSrcDir = Join-Path -Path 'src' -ChildPath $ProjectName >> New-Item -Path $projectSrcDir -ItemType Directory -Force | Out-Null >> >> # .csproj文件 >> Set-Content -Path "$projectSrcDir\$ProjectName.csproj" -Value @' >> <Project Sdk="Microsoft.NET.Sdk.Web"> >> <PropertyGroup> >> <TargetFramework>net8.0</TargetFramework> >> </PropertyGroup> >> </Project> >> '@ >> # Program.cs文件 >> Set-Content -Path "$projectSrcDir\Program.cs" -Value @' >> var builder = WebApplication.CreateBuilder(args); >> var app = builder.Build(); >> >> app.MapGet("/", () => "欢迎来到 $ProjectName"); >> >> app.Run(); >> '@ >> } >> } >> >> # 创建.gitignore文件 >> Set-Content -Path '.gitignore' -Value @' >> # 忽略日志文件 >> logs/ >> *.log >> >> # 忽略编译输出 >> bin/ >> obj/ >> dist/ >> build/ >> >> # 忽略环境文件 >> .env >> .venv >> >> # 忽略IDE设置 >> .vscode/ >> .idea/ >> '@ >> >> # 创建VS Code工作区 >> Set-Content -Path "$ProjectName.code-workspace" -Value @' >> { >> "folders": [ >> { >> "path": "." >> } >> ], >> "settings": { >> "files.exclude": { >> "**/.git": true, >> "**/.svn": true, >> "**/.hg": true, >> "**/CVS": true, >> "**/.DS_Store": true, >> "**/Thumbs.db": true >> } >> } >> } >> '@ >> >> Write-Host "✅ Project '$ProjectName' created at: $projectDir" -ForegroundColor Green >> Write-Host "🛠 Open project in VS Code with:" -ForegroundColor Cyan >> Write-Host " code '$ProjectName.code-workspace'" -ForegroundColor Yellow >> } >> PS C:\Users\Administrator> # 1. 导航到脚本目录 >> cd E:\ProjectEcosystem\ProjectMonitor >> >> # 2. 点导入脚本(注意空格) >> . .\Initialize-DevEnv.ps1 >> >> # 3. 创建项目(使用英文名称避免路径问题) >> Initialize-Project -ProjectName "MyWebApp" -ProjectType "web" >> Initialize-Project -ProjectName "DataAnalysis" -ProjectType "python" >> Initialize-Project -ProjectName "APIServer" -ProjectType "node" >> Initialize-Project -ProjectName "BackendService" -ProjectType "dotnet" >> >> # 4. 打开项目 >> code .\MyWebApp\MyWebApp.code-workspace >> Export-ModuleMember : 只能从模块内调用 Export-ModuleMember cmdlet。 所在位置 E:\ProjectEcosystem\ProjectMonitor\Initialize-DevEnv.ps1:199 字符: 1 + Export-ModuleMember -Function Initialize-Project + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (:) [Export-ModuleMember], InvalidOperationException + FullyQualifiedErrorId : Modules_CanOnlyExecuteExportModuleMemberInsideAModule,Microsoft.PowerShell.Commands.Expo rtModuleMemberCommand 鉁?椤圭洰 'MyWebApp' 宸插垱寤哄湪: E:\ProjectEcosystem\ProjectMonitor\MyWebApp 馃洜 浣跨敤浠ヤ笅鍛戒护鍦╒S Code涓墦寮€椤圭洰: code 'MyWebApp.code-workspace' 鉁?椤圭洰 'DataAnalysis' 宸插垱寤哄湪: E:\ProjectEcosystem\ProjectMonitor\DataAnalysis 馃洜 浣跨敤浠ヤ笅鍛戒护鍦╒S Code涓墦寮€椤圭洰: code 'DataAnalysis.code-workspace' 鉁?椤圭洰 'APIServer' 宸插垱寤哄湪: E:\ProjectEcosystem\ProjectMonitor\APIServer 馃洜 浣跨敤浠ヤ笅鍛戒护鍦╒S Code涓墦寮€椤圭洰: code 'APIServer.code-workspace' 鉁?椤圭洰 'BackendService' 宸插垱寤哄湪: E:\ProjectEcosystem\ProjectMonitor\BackendService 馃洜 浣跨敤浠ヤ笅鍛戒护鍦╒S Code涓墦寮€椤圭洰: code 'BackendService.code-workspace' PS E:\ProjectEcosystem\ProjectMonitor\BackendService> 弹出来了个窗口 写着发行说明1.13.0 (全是英文我没爱看 也看不懂)还有个”{}MyWebApp.code-workspace 打开聊天(ctrL+I)、选择语言(ctrl+K M)或使用模板填充(undefined)以开始使用。 开始输入以关闭或不再显示此信息。“
最新发布
08-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值