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;
}
}
}
問題和代碼都在這裡了 求大神