用反射机制来保存对象到数据库

作者:yaya | 时间:2008年11月29日 | 分类 学海无涯 | 标签 .net 反射 对象 数据库 学习 项目 | 3回复

哈哈,今天刚刚弄好用反射机制来保存对象到数据库(MSSQL2005) 虽然保存的对象要是遇到复杂的情况还是要出问题,但一般的包括引用类型在内的都可以搞定。 现在有时间就继续完备,算是超级轻量级的对象数据库关联了。 不知道真正的对象数据库什么时候才真正普遍起来。现在在OO与关系数据库中间,不论做什么转换工作,其效率都是不高的。 只有直接才有高效率。 在程序中有意义的地方: Object o = System.Reflection.Assembly.Load().CreateInstance()(对于动态生成对象还是用反射简单) 我觉得最好这样,比直接createInstance好,这样对不同的程序集也可以轻松创建实例。 而对于函数默认参数,用重载就可以了。 而对于Object o的赋值(假设o是创建的A),直接调用A的方法属性是不行的,而也不需要动态的将object换行成A,用setvalue就可以了。 支持所以A的方法和属性。 在最后显示的转换要还原的对象就可以了。

Incorrect syntax near the keyword User

作者:yaya | 时间:2008年7月17日 | 分类 随便写写 | 标签 keyword User 数据库 错误 问题 | 1回复

        不知怎么回事,非要去建立个user表,然后就出错了。网上一捞:

摘自:http://blog.csdn.net/sanking/archive/2007/10/31/1860190.aspx

Today I built one table named 'User' in sqlserver2000 and  found one problem.

When I type select * from User at SQL Query Analyzer, one message displayed as below:

Server: Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'User'.

O…I see "User" is the keyword of sql. So don't build User table into sql. If u must build one table named User.

The query should be  select * from "User"

But If in your java codes or other codes, how to do? I think it must be very complex..so…don't build User table in SQLserver2000.

But if u really must be use User table in programs.

The query statement should be  "select * from \"User\""  (Java)

In fact all the query statement can be "select * from \""+tableName+"\""

  1. 1