title: F# SqlCommand dynamically write to SQL table
body: <p>So I'm trying to Get data from one table (table1) then write selected data to a second table (table2). I'm able to get the data from table1 and select the data I want. I'm having trouble writing it to table2.</p>
  
  <p>This is what I have at the moment:</p>
  
  <pre><code>let insertData(data: string []List) =
  
      let tableName = data.Item(0).GetValue(0).ToString() //Gets the table Name
      let columnTypes = GetDevTableColumnsTypes tableName
  
      let mutable tableDataTemp = List.empty
      for i = 0 to data.Length-1 do
          let mutable rowDataTemp = List.empty
  
          for j = 0 to data.Item(i).Length-1 do
              if data.Item(i).GetValue(j).Equals(tableName) then //if statement removes table name from string array.
                  System.Diagnostics.Debug.WriteLine("tableName removed from data")
              else
                  let cellData = data.Item(i).GetValue(j)
  
                  rowDataTemp &lt;- cellData :: rowDataTemp
  
          let rowData = rowDataTemp |&gt; List.toArray |&gt; Array.rev
          tableDataTemp &lt;- rowData :: tableDataTemp
  
      let tableData = tableDataTemp |&gt; List.toArray |&gt; Array.rev //Probably unneeded
  
      let cn = new SqlConnection(Settings.Azure.SQL.CCSettingDev)
      cn.Open()
      let sQL = "INSERT INTO [" + tableName + "] VALUES(@param1)"
      let db = new SqlCommand(sQL, cn)
      db.Parameters.AddWithValue("@param1", tableData)
      db.ExecuteNonQuery()
  </code></pre>
  
  <p>When I run the code I get this argument exception pointed at the executeNonQuery:</p>
  
  <p>An exception of type 'System.ArgumentException' occurred in System.Data.dll but was not handled in user code</p>
  
  <p>Additional information: No mapping exists from object type System.Object[] to a known managed provider native type.</p>
  
  <p>Now at the moment I'm only working with 2 tables but soon the program is going to be working with multiple tables with different column names so I need this to work regardless of the table it's writing to. table1 and table2 have the same columns. tables 3 and 4 have the same columns as each other but they have different columns to tables 1 and 2.</p>
  
  <p>chosenData is an object array that contains other object arrays.</p>
  
  <p>If you think there's a better way of adding the data instead of adding an array, please let me know.</p>
  
  <p>Any help would be appreciated.</p>