• PostgreSQL中表和字符串大写的问题


    在PostgreSQL中,如果表名或者字段名中存在大写字符,这个sql执行就会错误。

    解决方法:

      给带有大写字母的表名或者字段名加上引号。

      eg:

        "Employee"

        "Name"

    这种情况在客户端编程也一样,如果是C#客户端,也必须加上引号。

     我们创建一个如下的表:

    CREATE TABLE "Employee"
    (
      "Name" 
    character varying(20),
      "Age" 
    integer,
      "Id" serial 
    NOT NULL
    )
    WITH (OIDS=FALSE);
    ALTER TABLE "Employee" OWNER TO postgres;

     C#客户端代码如下:

    protected void btnInsert_Click(object sender, EventArgs e)
           {
                
    string sql = "insert into \"Employee\"(\"Name\", \"Age\") "
                           
    + "values('" + txtName.Text + "', " + txtAge.Text + ")";
                
    //string sql = "insert into Employee(Name, Age) "
                
    //           + "values('" + txtName.Text + "', " + txtAge.Text + ")";
                PostSqlUtil db = new PostSqlUtil();
                
    if (db.ExecuteSQL(sql) > 0)
                    Response.Write(
    "一条记录插入成功!");
                
    else
                    Response.Write(
    "记录插入失败!");

            }

    技术改变世界
  • 相关阅读:
    Mongodb在windows下的安装和启动
    git操作的常用命令
    删除smartygit的配置文件
    注册树模式
    关于js的一些基础知识点
    关于mysql的初步学习 (五)
    关于mysql的初步学习 (四)
    关于mysql的初步学习 (三)
    关于mysql的初步学习 (二)
    关于数据库建表时的有趣实例--关键字重复
  • 原文地址:https://www.cnblogs.com/davidgu/p/2068545.html
Copyright © 2020-2023  润新知