Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>When you say "to convert all the rows", do you actually mean "to convert all the <strong>columns</strong>"? </p> <p>I so, and if your ADO.NET provider supports it, you can use <em>LINQ to SQL</em> to auto-generate a class that has properties that match the columns in your table. You can follow this procedure:</p> <ol> <li>Right-click on your project and Add / New Item / LINQ to SQL Classes. By default, this will generate a DataClasses1.dbml file with <code>DataClasses1DataContext</code> class.</li> <li>Expand the database connection of interest in the Server Explorer, under Data Connections (you may need to add it there first through right-click on Data Connections).</li> <li>Pick the table of interest and drag'n'drop it onto the surface of DataClasses1.dbml.</li> </ol> <p>Assuming your table name was COUNRTY with fields NAME and CODE, you can then use it from your code like this:</p> <pre><code>using (var db = new DataClasses1DataContext()) { COUNRTY egypt = db.COUNRTies.Where(row =&gt; row.NAME == "Egypt").SingleOrDefault(); if (egypt == null) { // "Egypt" is not in the database. } else { var egypt_code = egypt.CODE; // Use egypt_code... } } </code></pre> <hr> <p>If you actually meant "rows", I'm not aware of an automated way to do that (which doesn't mean it doesn't exist!). Writing a small program that goes through all rows, extracts the actual values and generates some C# text should be a fairly simple exercise though.</p> <p>But even if you do that, how would you handle database changes? Say, a value is deleted from the database yet it still exists in your program because it existed at the time of compilation? Or is added to the database but is missing from your program?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload