sql server - Cannot search query SQL DB -
sql server - Cannot search query SQL DB -
my understanding of coding , databases in limited, spent couple weeks reading tutorials , borrowing code. after attempting write own have nail brick wall , borrowed/adapted code. have database called 'sourcing matrix' table called 'fish'. want able search db 'cod' , have display cod stock. code have adapted throwing error , cannot figure out why, have tried number of different column names, rearranged code, tried google, tried limited knowledge suggest.
when click seek , go search page default.cshtml throws error.
this code search page:
@{ page.title = "filter webgrid"; var db = database.open("sourcing matrix"); var query = "select distinct [common name] fish order [common name]"; var fish = db.query(query); query = "select * fish [common name] @0 , [latin name] @1"; var commonname = "%" + request["[common name]"] + "%"; var latinname = "%" + request["[latin name]"] + "%"; var info = db.query(query, commonname, latinname); var columns = new[]{"fishid", "[common name]", "[latin name]", "[method of production]", "[catch area]", "[country of production (farmed)]", "[area detail]", "[stock detail]","[method of capture / production]","accreditation","[certifying body]","[msc rating]","[other rating]","[do shl source?]","reason"}; var grid = new webgrid(data, columnnames: columns, rowsperpage: 35); } <h1>filter webgrid</h1> <form method="post"> <div id="grid"> mutual name: <input type="text" name="commonname" value="@request["[common name]"]" /> latin name: <select name="latinname"> <option></option> @foreach(var item in fish){ <option @(request["[latin name]"] == item.latinname ? " selected=\"selected\"" : "")>@item.latinname</option> } </select> <input type="submit" /> @grid.gethtml( tablestyle : "table", alternatingrowstyle : "alternate", headerstyle : "header", columns: grid.columns( grid.column("fishid", "id"), grid.column("commonname", "[common name]"), grid.column("latinname", "[latin name]"), grid.column("[method of production]"), grid.column("[catch area]"), grid.column("[country of production (farmed)"), grid.column("[area detail]"), grid.column("[stock detail]"), grid.column("[method of capture / production]"), grid.column("accreditation"), grid.column("[certifying body]"), grid.column("[msc rating]"), grid.column("[other rating]"), grid.column("[do shl source?]"), grid.column("reason") ) ) </div> </form> @section script{ <script type="text/javascript"> $(function(){ $('th a, tfoot a').live('click', function() { $('form').attr('action', $(this).attr('href')).submit(); homecoming false; }); }); </script> }
this error throws up:
invalid column name "latinname". description: unhandled exception occurred during execution of current web request. please review stack trace more info error , originated in code.
exception details: system.invalidoperationexception: invalid column name "latinname".
source error:
line 34: line 35: @foreach(var item in fish){ line 36: @item.latinname line 37: } line 38:
source file: c:\users\cbond\documents\my web sites\emptysite\sfish2.cshtml line: 36
there column named 'latin name', cannot understand why doesnt recognise so?! sorry if silly question or answered. still trying grasps coding business! all. :)
sql sql-server database
Comments
Post a Comment