Wednesday 15 June 2011

Using a SQL Table instead of a Dictionary Reference in C# -


I now have all my data that gives me a separate class device and within that class There is a dictionary & lt; Int, string & gt; MyTools . I have heard that for future use, it would be better to store it in a table within the SQL database.

What I have now here:

  Public stable dictionary & lt; Int, string & gt; MyTools = New Dictionary & lt; Int, string & gt; () {{1001, "Tool 1"}, {1002, "Tool 2"}, {1003, "Tool 3"}, //..and so on ...}   < P> With this in my program, I am able to reference the corresponding integer and the string "name" is connected to the integer that uses something like this:  tool. MyTools [1002] . I like this method because I can easily change the names of the tools without changing the way they are called to change them. However, I would eventually like to control device names for all programs through a database, and this is why I basically want to copy this dictionary to a SQL server. I think this is done as a table, but I have experience of SQL Server Management Studio, and that's why I'm coming here for help.  

What should I know: How can I create a table in SQL which gives me permission to reference tools from my respective integer as I am already doing ? If it is so easy to copy all the data into a table and then it refers to a slightly different function, I apologize for the simple question, and a simple answer will still be welcome!

Thanks in advance!

Edit: Apparently I did not give enough credit to myself I already have a table in a database through SQL Server Management Studio in this table There are only two columns, numbers and names . If this is wrong then I was asking what should I do to change or fix it, and then if it is correct then I want to know what to do in the visual studio so that I can refer to these devices Like I can do with the dictionary, it is actually as simple as importing databases and then it's db.Tools. [Number] or something like that?

I will advise to do some unit structure chores, special code first.

When you learn how to make models, this will be a good starting point for your model:

  class tool {int toolId {get; Set;} string name {to capture a specific device  
  get the tool myTool = db.Tools.Single (t = & gt; t.ToolId ==); Set;}}   

theVariableWithToolIdIWant); String theNameOfTheTool = myTool.Name;

This will not take much meaning at the moment, but when you go through some tutorials and set up your database context, hopefully what you want to do.

No comments:

Post a Comment