c#中的Postgresql Npgsql.PostgresException
发布时间:2020-12-15 21:04:18 所属栏目:百科 来源:网络整理
导读:我有cmd.ExecuteReader()的问题我得到一个Npgsql.PostgresException public void connectDB() { try { server = "localhost"; database = "DoveVer3"; uid = "admin"; password = "admin"; string connectionString; connectionString = "Host=" + server +
我有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); } } 我在下面的代码中获得了Exeption: 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在这里是我的表代码: 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; 例外基础信息:
解决方法
默认情况下,传递给PostgreSQL的所有标识符都将被视为小写.根据您的创建脚本,在定义表时使用了
quoted-identifer,因此在使用表名时需要以下内容.
SELECT * FROM "DoveTable" 请注意,它用双引号括起来,’D’和’T’都是大写的.使用带引号的标识符时,必须始终按照定义它们的方式将它们写出来. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |