开发者

How can I read Database Tables with Attributes

I want to read database tables with Attributes. I have Table in database and I have class same fields name. I want to transfer to my class which matched values in database using attributes.

For Example :

[ReadDBAttributes]
public class News{
   public string Title;
   public s开发者_高级运维tring Content;
}

How can I do it?


Assuming MySQL you'll need a table

CREATE TABLE IF NOT EXISTS News 
   (Id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, Title VARCHAR(20), Content Text);

Then you'll insert your data using escaped values where noted.

INSERT INTO News (Title, Content) VALUES ('[ESCAPED TITLE]', '[ESCAPED CONTENT]')

You can then read these back out in any number of ways (this assumes MySQL).

-- get most recent news
SELECT Title, Content FROM News ORDER BY Id DESC LIMIT 1

-- get a specific item by id
SELECT Title, Content FROM News WHERE Id = [ID YOU WANT]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜