Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So, the first problem you have is that your code is not doing what you think it does.The big problem is that you are reading in all the text and then only ever selecting the first three values of it.You don't give the format of your data, but suppose it looks like this:</p> <pre><code>Scotland*Edinburgh*Midlothian* Scotland*Perth*Perthshire* </code></pre> <p>Your code</p> <pre><code>string groups = File.ReadAllText(ofdFile.FileName); </code></pre> <p>Reads the whole file into one string, such that it will look like this</p> <pre><code>Scotland*Edinburgh*Midlothian*\r\nScotland*Perth*Perthshire* </code></pre> <p>So splitting it using the following</p> <pre><code>string[] parts = groups.Split(new char[] { '*' }, StringSplitOptions.RemoveEmptyEntries); </code></pre> <p>gives you a string array of 6 parts. Inserting multiple lines from this is doable but won't be very neat. You'd be much better to read your text files in by lines, and then iterate over the array of lines, splitting each one as you go and then adding the relevant parts to SQL. Something like</p> <pre><code>string[] lines = System.IO.File.ReadAllLines(ofdFile.FileName); foreach (var line in lines) { string[] parts = line.Split('*'); AddtoSQL(parts[0], parts[1]); } </code></pre> <p>That should insert all the data, but as an aside, if you are looking to execute numerous inserts at once, I'd recommend housing those inserts inside of a SQL Transaction.</p> <p>I'd direct you to have a look at <a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqltransaction.aspx" rel="nofollow">this MSDN article on the SqlTransaction Class</a></p> <p>The gist of it is that you declare a transaction first, then loop over your inserts executing those against the transaction. Finally, when you commit your transaction the queries are all written to the database en mass. The reason I'd do this is that it will be much quicker and safer.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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