放縱與他溫馨 2019-05-14 21:00 采纳率: 0%
浏览 377

如何解决shape文件转sql文件中属性的中文乱码问题

图片说明

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;


namespace sjk
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private string pTransPath = "";
        private string path = "";
        OpenFileDialog openFileDialog = new OpenFileDialog();

        private void Form1_Load(object sender, EventArgs e)
        {
        }

        private void button2_Click_1(object sender, EventArgs e)
        {
            openFileDialog.DefaultExt = "shp";
            openFileDialog.Filter = "shp文件(*.shp)|*.shp";
            path = textBox1.Text;
            if (openFileDialog.ShowDialog() != DialogResult.Cancel)
            {
                pTransPath = openFileDialog.FileName;
                textBox1.Text = openFileDialog.FileName;
            }
        }

        private void button1_Click_1(object sender, EventArgs e)
        {

            pTransPath = textBox1.Text;
            path = textBox1.Text + ".sql";
            System.Diagnostics.Process p = new System.Diagnostics.Process();
            if (radioButton1.Checked)
            {
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.Start();
                p.StandardInput.WriteLine(@" D:\PostgreSQL\9.3\bin\shp2pgsql.exe C:\Users\Administrator\Desktop\实验1\shapefiles\airports.shp > C:\Users\Administrator\Desktop\实验1\shapefiles\airports.sql ");
                p.StandardInput.WriteLine("exit");
                //string output = p.StandardOutput.ReadToEnd(); 
                p.WaitForExit();
                MessageBox.Show("转换成功", "转换提示");
            }
            else
            {
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.Start();
                p.StandardInput.WriteLine(@" D:\MySQL\Mysql\shp2mysql.exe C:\Users\Administrator\Desktop\实验1\shapefiles\airports.shp > C:\Users\Administrator\Desktop\实验1\shapefiles\airports.sql ");
                p.StandardInput.WriteLine("exit");
                //string output = p.StandardOutput.ReadToEnd(); 
                p.WaitForExit();
                MessageBox.Show("转换成功", "转换提示");
            }
        }
    }
}
  • 写回答

1条回答 默认 最新

  • 憧憬blog 2023-03-15 07:24
    关注

    你好,针对你的问题,中文乱码问题,可能是由于数据源文件中的字符集和转换后的 SQL 文件的字符集不一致导致的。你可以尝试在命令行窗口中使用 -W 参数指定字符集,例如 -W "GB2312"。
    另外,需要确保系统、数据库、数据库表和字段的字符集都相同,否则可能会出现乱码等问题。
    同时,你的代码中似乎没有对读取的 shape 文件进行编码设置,你可以在读取 shape 文件时,使用相关的编码设置,例如:

    StreamReader reader = new StreamReader(pTransPath, System.Text.Encoding.Default);
    

    希望这些信息可以帮助你解决问题。

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)