开发者

How to retrieve items from a database c#

I have three tables "pics", "shows", "showpics".

I want to be able to edit the table "shows". In order to do this I need to retrieve the pictures that the show contains (the pictures are stored in the table "pic开发者_Go百科s").

The "showpics" table acts as a link.

Does anyone have any ideas as I'm completely lost and have no idea where to even start


I think you need to learn about how to talk to the database - perhaps this tutorial on ADO.NET would be a good place to start.

ADO.NET is an object-oriented set of libraries that allows you to interact with data sources. Commonly, the data source is a database, but it could also be a text file, an Excel spreadsheet, or an XML file. For the purposes of this tutorial, we will look at ADO.NET as a way to interact with a data base.


Also, here is a tutorial on Linq

http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx

If you have not used ADO.NET it might be a bit easier to go the declarative route.

Linq can query a database with much less code and Linq will perform much of the interface code for you.

Here is a link on how to read and write blobs in oracle http://www.oracle.com/technology/sample_code/tech/windows/odpnet/howto/anonyblock/index.html


Read on how to read and write BLOB with ADO.NET and C# here.


There are many different approaches to retrieve data from the database.

I would use LINQ to SQL for a Microsoft SqlServer database.

Here is a good tutorial: http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx


Using SQL, you would do something like this, e.g., for show ID 27:

select p.* 
from pics p
inner join showpics sp on p.PicID = sp.PicID
inner join shows s on sp.ShowID = s.ShowID
where s.ShowID = 27


If the pictures are large (more than 30Kb or so) you really don't want to put them into a DataSet... this was a reliable way to crash a server with OOM errors for me on an app I worked on. To deal with large pictures, you will want to stream them into and out of the database...

here is a link to get you started on streaming, or better yet, just don't use images more than 30kb or so, else put them on the filesystem, not in tables:

http://msdn.microsoft.com/en-us/library/3517w44b.aspx

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜