Answered by:
No mapping exists from DbType System.Collections.ObjectModel.ReadOnlyCollection`1[System.Object] to a known SqlCeType.

Question
-
User1493762548 posted
hi anyone help me .there is error in line 90. the given code is the part of addProducts.cshtml . after filling the information in form when click next the error occur.
here is error :
Server Error in '/' Application.
No mapping exists from DbType System.Collections.ObjectModel.ReadOnlyCollection`1[System.Object] to a known SqlCeType.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: No mapping exists from DbType System.Collections.ObjectModel.ReadOnlyCollection`1[System.Object] to a known SqlCeType.
Source Error:
Line 88: Line 89: var insertCommand = "INSERT INTO Products (ProductTitle,ProductType, CategoryId,Details,ContactNo,CityId,CityName, ProductPrice,UserId,newFileName , UploadDate,status) Values(@0, @1, @2,@3,@4,@5,@6,@7,@8,@9,@10,@11)"; Line 90: db.Execute(insertCommand, ProductTitle,ProductType,CategoryId,Details,ContactNo,CityId,CityName, ProductPrice,UserId,newFileName,DateTime.Now,status); Line 91: Line 92: //--------------- ----------------------
Source File: c:\Users\fiaz ranjha\Documents\My Web Sites\Photo Gallery\AddProducts.cshtml Line: 90
Stack Trace:
[ArgumentException: No mapping exists from DbType System.Collections.ObjectModel.ReadOnlyCollection`1[System.Object] to a known SqlCeType.] System.Data.SqlServerCe.SqlCeType.FromClrType(Object value) +300918 System.Data.SqlServerCe.SqlCeParameter.set_Value(Object value) +36 WebMatrix.Data.<>c__DisplayClass12.<AddParameters>b__11(Object o, Int32 index) +109 System.Linq.<SelectIterator>d__5`2.MoveNext() +187 WebMatrix.Data.Database.AddParameters(DbCommand command, Object[] args) +169 WebMatrix.Data.Database.Execute(String commandText, Object[] args) +102 ASP._Page_AddProducts_cshtml.Execute() in c:\Users\fiaz ranjha\Documents\My Web Sites\Photo Gallery\AddProducts.cshtml:90 System.Web.WebPages.WebPageBase.ExecutePageHierarchy() +196 System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors) +68 System.Web.WebPages.WebPage.ExecutePageHierarchy() +151 System.Web.WebPages.StartPage.RunPage() +19 System.Web.WebPages.StartPage.ExecutePageHierarchy() +62 System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) +76 System.Web.WebPages.WebPageHttpHandler.ProcessRequestInternal(HttpContextBase httpContext) +114
ProductTitle = Request.Form["ProductTitle"]; CategoryId = Request.Form["categoryId"]; Details = Request.Form["Details"]; ContactNo=Request.Form["ContactNo"]; ProductPrice = Request.Form["ProductPrice"]; ProductType=Request.Form["ProductType"]; CityId=Request.Form["cityId"]; var sql="SELECT CityName FROM City where CityId=@0"; var CityName = db.Query(sql,CityId); var insertCommand = "INSERT INTO Products (ProductTitle,ProductType, CategoryId,Details,ContactNo,CityId,CityName, ProductPrice,UserId,newFileName , UploadDate,status) Values(@0, @1, @2,@3,@4,@5,@6,@7,@8,@9,@10,@11)"; db.Execute(insertCommand, ProductTitle,ProductType,CategoryId,Details,ContactNo,CityId,CityName, ProductPrice,UserId,newFileName,DateTime.Now,status);
Wednesday, June 15, 2016 12:45 PM
Answers
-
User379720387 posted
db.Query gives a set of records
db.QuerySingle gives a single record
db.QueryValue gives a column from a single record
The helper knows what the result is (records, record, value) and if the query type doesn't match it throws all sorts of errors that don't seem to make much sense
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, June 16, 2016 12:25 AM
All replies
-
User379720387 posted
Are you column names correct for this table?
Wednesday, June 15, 2016 3:59 PM -
User1493762548 posted
yes columns are correct . if i remove CityName from insertCommand and db.execute command lines and remove the
var sql="SELECT CityName FROM City where CityId=@0";
var CityName = db.Query(sql,CityId);
the code works correctly
there is error in this section of code.
CityId=Request.Form["cityId"];
var sql="SELECT CityName FROM City where CityId=@0"; var CityName = db.Query(sql,CityId);Wednesday, June 15, 2016 4:42 PM -
User1493762548 posted
if i replace the said code with :
CityId=Request.Form["CityId"]; var c = db.QuerySingle("SELECT CityName FROM City where CityId=@0,CityId"); var CityName =c.CityName;
the error is :
very very thanks for your patience and response .
There was an error parsing the query. [ Token line number = 1,Token line offset = 42,Token in error = , ]
error on the line below:
var c = db.QuerySingle("SELECT CityName FROM City where CityId=@0,CityId");
Please Note: in the submitted form input field has name="CityId"
Wednesday, June 15, 2016 4:49 PM -
User1493762548 posted
hi all, issue solved and worked well by replacing the above code with :
var p = db.QuerySingle("SELECT * FROM City WHERE CityId = @0", CityId); var CityName =p.CityName;
can anyone tell what the reason was? because it can help others .
lot of thanks .how helpful people you are? i am happy with you all.
Wednesday, June 15, 2016 5:05 PM -
User379720387 posted
db.Query gives a set of records
db.QuerySingle gives a single record
db.QueryValue gives a column from a single record
The helper knows what the result is (records, record, value) and if the query type doesn't match it throws all sorts of errors that don't seem to make much sense
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, June 16, 2016 12:25 AM