Wednesday, March 21, 2012

Odd SqlException

I'm using .NET 2.0

I designed my BLL to work as follows:

'Update existing company <System.ComponentModel.DataObjectMethodAttribute _ (System.ComponentModel.DataObjectMethodType.Update,True)> _Public Function UpdateCompany(ByVal Original_CompanyIDAs Int64, ...)As Boolean'Get current recordDim CompaniesAs biodata.CompaniesDataTable = CompaniesAdapter.GetCompanyByID(Original_CompanyID)'If no record exists, Update failsIf Companies.Count = 0Then Throw New ApplicationException("Company does not exist.")End If Dim CompanyAs biodata.CompaniesRow = Companies(0)'Set all the values to load into the database Company.CompanyName = CompanyName ...Dim RowsAffectedAs Integer = CompaniesAdapter.Update(Company)Return (RowsAffected = 1)End Function

Recently I deleted a column in my SQL database. In order to account for this change, I deleted the same column in my DAL. Then, because of the obvious compile errors that would occur if I didn't, I deleted all references to that column in my BLL. My DAL automatically creates the Update and Insert statements. Now, the error I'm getting is as follows:

Exception Details:System.Data.SqlClient.SqlException: Cursorfetch: The number of variables declared in the INTO list must match that of selected columns.
The statement has been terminated.

Source Error:

Line 18409: System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")> _Line 18410: Public Overloads Overridable Function Update(ByVal dataRow As System.Data.DataRow) As IntegerLine 18411: Return Me.Adapter.Update(New System.Data.DataRow() {dataRow})Line 18412: End FunctionLine 18413:

Stack Trace:

[SqlException (0x80131904): Cursorfetch: The number of variables declared in the INTO list must match that of selected columns.The statement has been terminated.] System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount) +200 System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount) +104 System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping) +3042 System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows) +345 biodataTableAdapters.CompaniesTableAdapter.Update(DataRow dataRow) in C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\67b7db20\aea00f88\App_Code.nf1apfb7.1.vb:18411 CompaniesBLL.UpdateCompany(Int64 Original_CompanyID, String CompanyName, String Division, String Website, Nullable`1 CompanyInactive, String CompanyInactiveReason, Nullable`1 EmployeeCount, Nullable`1 YearFounded, Nullable`1 YearStartedBiobased, Nullable`1 NAICS, String Address1, String Address2, String City, String StateCode, String Territory, String CountryCode, String Zip, String CompanyNotes, String Prefix, String FName, String LName, String Suffix, String Title, String Email, String Phone1, String PhoneType1, String Phone2, String PhoneType2, String Phone3, String PhoneType3, String UpdateType, String UpdatedBy, Int64 SecurityLevel, Int64[] Flags) in F:\App_Code\BLL\CompaniesBLL.vb:376

Now, this exception makes no sense to me because the DAL should automatically fix the update and insert statements itself, and I never directly access those statements. The error is occuring at CompaniesAdapter.Update(Company) in my code above. Any ideas?

Thanks,
BSY E-718

Turn on SQL Profiler... and watch the actual query that is being executed... that might point you in the right direction.

No comments:

Post a Comment