gpt4 book ai didi

c# - C# 中的 Postgresql Npgsql.PostgresException

转载 作者:行者123 更新时间:2023-11-29 11:37:22 26 4
gpt4 key购买 nike

我有一个 cmd.ExecuteReader() 的问题,我得到一个 Npgsql.PostgresException

    public void connectDB()
{
try
{
server = "localhost";
database = "DoveVer3";
uid = "admin";
password = "admin";
string connectionString;
connectionString = "Host=" + server + ";Username =" + uid + ";" + "PASSWORD=" + password + ";DATABASE=" + database;

connection.ConnectionString = connectionString;
connection.Open();

}
catch (Exception e)
{
MessageBox.Show(e.Message);

}


}

我在下面的代码中得到了异常:

  public void AddDoveToDB(Dove dove)
{
//add new dove record to tableDB
connectDB();
cmd = new NpgsqlCommand();
cmd.Connection = connection;
cmd.CommandText = "SELECT * FROM " + DoveTableDB + " WHERE `" + DoveIdColumnDoveTable + "` = '" + dove.GetDoveId() + "'";
NpgsqlDataReader rdr = cmd.ExecuteReader(); //// <<<<< HERE
if (rdr.Read() != true)
{
rdr.Close();
cmd.Parameters.Clear();

cmd.CommandText = "INSERT INTO " + DoveTableDB + "(" + DoveIdColumnDoveTable + "," + DoveIdFatherColumnDoveTable + "," + DoveIdMotherColumnDoveTable + "," + DoveEyesColorColumnDoveTable + "," + DoveFeatherColorDoveTable + "," + DoveImageNameColumnDoveTable + "," + DoveSexColumnDoveTable +") VALUES ('" + dove.GetDoveId() + "','" + dove.GetDoveFatherId() + "','" + dove.GetDoveMotherId() + "','" + dove.GetEyesColor() + "','" + dove.GetFeathersColor()+ "','" + dove.GetImageName() + "','" + dove.GetSex()+ "')";
cmd.ExecuteNonQuery();

}
connection.Close();
}

我的数据库名为 DoveVer3,我的模式 DoveSchema 是我的表代码:

enter image description here

    Name: DoveTable; Type: TABLE; Schema: DoveSchema; Owner: admin
--

CREATE TABLE "DoveTable" (
"doveId" character varying(20)[] NOT NULL,
"doveFather" character varying(20)[],
"doveMother" character varying,
"doveEyesColor" character varying(20)[],
"doveFeathersColor" character varying(20)[],
"doveSex" smallint DEFAULT 3 NOT NULL,
"imageName" character varying(30)
);
ALTER TABLE "DoveTable" OWNER TO admin;

异常基础消息:

relation "dovetable" don't exist; Statemants: {SELECT * FROM DoveTable WHERE doveId = 'Test'}

最佳答案

默认情况下,所有传递给 PostgreSQL 的标识符都将被视为小写。根据您的创建脚本,您使用了 quoted-identifer在定义表格时,使用表格名称时需要以下内容。

SELECT * FROM "DoveTable"

请注意,它用双引号括起来,'D' 和 'T' 都是大写的。使用带引号的标识符时,您必须始终按照您定义它们的方式写出它们。

关于c# - C# 中的 Postgresql Npgsql.PostgresException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41203708/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com