baidu_28424025 2015-05-24 08:29 采纳率: 20%
浏览 3449
已采纳

c# 连接postgresql出现乱码问题

图片说明

public partial class test : System.Web.UI.Page
{
    private readonly string _strConn = "Server=192.168.0.107;Port=5432;User Id=postgres;Password=123;Database=TestDB;";
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            NpgsqlConnection conn = new NpgsqlConnection(_strConn);
            conn.Open();
            string sql = "select count(*) from Tdb";
            NpgsqlCommand cmd = new NpgsqlCommand(sql, conn);
            int n = cmd.ExecuteNonQuery();
            conn.Close();
            if (n > 0)
            {
                Label1.Text = "yes";
            }
            else
            {
                Label1.Text = "no";
            }
        }
        catch (Exception ex)
        {

            Label1.Text = ex.Message;
        }
    }
}

    问题和代码都在这里了 求大神
  • 写回答

3条回答 默认 最新

  • 知常曰明 2015-05-24 11:23
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?