开发者

Retrieving values from SQL Server

My table in SQL Server has 3 fields

serial no. (int)
days       (varchar)
status     (bit)

With the help of a dictionary how can I retrieve days and status as a 开发者_StackOverflow中文版key-value pair from SQL Server using a SqlDataReader?


This seems very much like homework, so here's some pseudocode to help you towards the answer:

  1. Create a Dictionary to hold the values you retrieve.
  2. Open a database connection.
  3. Create a SqlCommand that selects the relevant values out of the table
  4. Create a SqlDataReader using the SqlCommand created previously.
  5. Iterate over the reader using its .Read method.
    1. Get the Day field and Status field and put them in the dictionary
    2. Repeat step 1 until .Read returns false
  6. You're done!

I've put a large number of links to pages on msdn.microsoft.com into the steps I've detailed. By reading through those, and looking at the code samples that are present on each page, you should be able to put together some working code =)


Dictionary<int, Dictinary<string,bool> dict=new Dictionary<int, Dictinary<string,bool>;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜