Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding Multiple values to SQL Server table
    primarykey
    data
    text
    <p>First off I'd like to apologize if this is more of a question than an example but I'm really lost here. I have a Windows Form that loads info from a text file. In each text file there is all the cities and counties in a given state, each section is separated by the <code>.Split</code>. I have a <code>SQL Server 2008</code> database, 2 columns, Name and type. What I'd like to do is take all of the information and add it too individual rows with the name column being the name and the type column being state or county. Here is how I have the information split. How would I add a new row for each entry in the text?</p> <pre><code>void PopulateZones() { ofdFile.Filter = "Text File (.txt)|*.txt|All Files (*.*|*.*"; ofdFile.FilterIndex = 1; ofdFile.Multiselect = true; ofdFile.FileName = String.Empty; if (ofdFile.ShowDialog() == DialogResult.OK) { ofdFileLocTextBox.Text = ofdFile.FileName.ToString(); string groups = File.ReadAllText(ofdFile.FileName); string[] parts = groups.Split(new char[] { '*' }, StringSplitOptions.RemoveEmptyEntries); stateTextBox.Text = parts[0]; citiesTextBox.Text = parts[1]; countiesTextBox.Text = parts[2]; AddtoSQL(parts[0], parts[1]); } } void AddtoSQL(string cities, string counties) { Sqlconnection conn = new SqlConnection(connString) Sqlcommand comm = new Sqlcommand("INSERT into [Table] (Name, Type) Values (@Name, @Type))"; comm.Parameters.Add(@Name, each line of textbox); comm.Parameters.Add(@Type, City or County); comm.ExecuteNonQuery(); } </code></pre>
    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.
 

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