Note that there are some explanatory texts on larger screens.

plurals
  1. POFailed to batch insert in Subsonic3 with error "Must declare the scalar variable..."
    primarykey
    data
    text
    <p>I have met a problem about inserting multiple rows in a batch with Subsonic3. My development environment includes:</p> <pre><code>1. Visual Studio 2010, but use .NET 3.5 2. Active Record Mode in SubSonic 3.0.0.4 3. SQL Server 2005 express 4. Northwind sample database </code></pre> <p>I am using Active Reecord mode to insert mutiple "Product" into table "Products". If I insert the rows one by one, either call "aProduct.Add()" or call "Insert.Execute()" mutiple times (just like the codes below), it works fine.</p> <pre><code> private static Product[] CreateProducts(int count) { Product[] products = new Product[count]; for (int index = 0; index &lt; products.Length; ++index) { products[index] = new Product { ProductName = string.Format("cheka-test-{0}", index.ToString()), Discontinued = (index % 2 == 0), }; } return products; } private static void SucceedByMultiExecuteInsert() { Product[] products = CreateProducts(2); // -------------------------------- prepare batch NorthwindDB db = new NorthwindDB(); var inserts = from prod in products select db.Insert.Into&lt;Product&gt;(x =&gt; x.ProductName, x =&gt; x.Discontinued).Values(prod.ProductName, prod.Discontinued); // -------------------------------- batch insert var selectAll = Product.All(); Console.WriteLine("--- before total rows = {0}", selectAll.Count().ToString()); foreach (Insert insert in inserts) insert.Execute(); Console.WriteLine("+++ after inserting {0} rows, now total rows = {1}", products.Length.ToString(), selectAll.Count().ToString()); } </code></pre> <p>but if I use "BatchQuery" like the codes below, </p> <pre><code> private static void FailByBatchInsert() { Product[] products = CreateProducts(2); // -------------------------------- prepare batch NorthwindDB db = new NorthwindDB(); BatchQuery batchquery = new BatchQuery(db.Provider, db.QueryProvider); var inserts = from prod in products select db.Insert.Into&lt;Product&gt;(x =&gt; x.ProductName, x =&gt; x.Discontinued).Values(prod.ProductName, prod.Discontinued); foreach (Insert insert in inserts) batchquery.Queue(insert); // -------------------------------- batch insert var selectAll = Product.All(); Console.WriteLine("--- before total rows = {0}", selectAll.Count().ToString()); batchquery.Execute(); Console.WriteLine("+++ after inserting {0} rows, now total rows = {1}", products.Length.ToString(), selectAll.Count().ToString()); } </code></pre> <p>then it failed with the exception : " <strong>Unhandled Exception: System.Data.SqlClient.SqlException: Must declare the scalar variable "@ins_ProductName". Must declare the scalar variable "@ins_ProductName".</strong> "</p> <p>Please give me some help to solve this problem. Many thanks.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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