Jump to content

kevin.upshaw

Members
  • Posts

    17
  • Joined

  • Last visited

About kevin.upshaw

  • Birthday 08/13/1992

kevin.upshaw's Achievements

Newbie

Newbie (1/7)

1

Reputation

  1. Hi, I wonder if someone can help. I am trying within a WebGrid to create a link on the (using the HTML anchor tag) Asset Tag column - so then when the user clicks on an asset tag it directs them to a Display Report page - where it displays a transaction report on that particular asset. I have searched and searched the internet, and found the solution below. However it displays the following error message: Server Error in '/' Application. Object reference not set to an instance of an object.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.NullReferenceException: Object reference not set to an instance of an object. Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Here is my code: var db = Database.Open("assetManagement"); var sqlExtractEventDescription = "SELECT * FROM [event]";}<h2>Devices</h2>@{if(addNewOutput.IsEmpty() == false){<p class="informationMessage">@addNewOutput</p><br />}}<a href="addNew.cshtml?type=device" class="button">Add New</a><a href="editExisting.cshtml?type=device" class="button">Edit Existing</a>@{var sql = "SELECT assetTag, imei, serialNumber, eventId FROM [device] ORDER BY assetTag";var data = db.Query(sql);var grid = new WebGrid(data, canPage: true, rowsPerPage: 10);grid.Pager(WebGridPagerModes.NextPrevious);}<div id="webGridDiv">@grid.GetHtml( tableStyle: "userWebGrid", htmlAttributes: new { id = "deviceDataTable" }, headerStyle: "header", alternatingRowStyle: "alt", columns: grid.Columns( grid.Column("assetTag", "Asset Tag", format: @<text><a class="button" href="@Href("~/reports/displayReport.cshtml?type=assetTag&assetTag=" + assetTag")">@assetTag</a></text>), grid.Column("imei", "IMEI"), grid.Column("serialNumber", "Serial Number"), grid.Column("eventId", "Event ID"), grid.Column("", "Edit"))) </div> If someone could perhaps point me in the right direction as to where I am going wrong that would be great. Thanks. Kevin
  2. Cracked it!It took someone else to go through it with me to realise what it is. I thought "transaction" and "user" were displayed in a colour they shouldn't be in on the WebMatrix software. So I created a bogus "transaction1" and "user1" table and put some fake data in them - then created the relationship between them. The query works absolutely fine now - so I'm guessing it was because I was using reserved words as my table names - will make sure I use proper names next time, would have saved so much time! Thank's very much for your help. Much appreciated. Kevin
  3. I receive the error: "Incorrect syntax near the keyword 'transaction'". I am using WebMatrix - Using ASP.NET Web Pages - Razor Syntax (C#). However I am trying to do the query ion the WebMatrix environment before trying to code it into a web page/ Am running SQL Express on my laptop. Could perhaps try installing Visual Studio 2010 and running the query from there?
  4. Hi, I tried the following: SELECT transaction.transactionId, user.firstName, user.lastNameFROM transactionINNER JOIN userON transaction.userId=user.userIdORDER BY user.userId No joy. It wouldn't perhaps be because my table names are reserved names? I know "user" is. Thanks. Kevin
  5. Hi.Wonder if you can help, am quite new to SQL. In simple terms, I have a transaction table - and in that table are references to other related tables. In this simple query I am trying to obtain the first name and last name from the user ID for a transaction. SELECT transaction.transactionId, user.firstName, user.lastNameFROM [transaction]INNER JOIN [user]ON transaction.userId = user.userIdORDER BY user.userId However I get the response "incorrect syntax near the keyword transaction". I then try: SELECT 'transaction'.transactionId, user.firstName, user.lastNameFROM [transaction]INNER JOIN [user]ON 'transaction'.userId = user.userIdORDER BY user.userId I then receive "cannot call methods on varchar" - which I am assuming SQL thinks I am referring to text - rather than table names. I then tried: SELECT dbo.transaction.transactionId, user.firstName, user.lastNameFROM [transaction]INNER JOIN [user]ON dbo.transaction.userId = user.userIdORDER BY user.userId However no joy - I get the initial error message. Is someone able to point me in the right direction as to where I am going wrong? I have quite a few joins I need to do - but I thought if I could get this fixed first that would be a start.Cheers. Kev
  6. Hi. Not quite sure where to start with this one. Am creating a website at the moment, and within that site - in my SQL Compact database I have a "transaction" table. There will be thousands of records in that table - what I want the user to be able to do is search based on a particular parameter - which is fine as I can just use SQL to obtain that information. However, say for instance it returns 100 records - I don't want to display all that data to a user all at once. How would I go about creating a facility to navigate on a table? For instance so it displays ten records at a time? I am using WebMatrix to create this site. Thanks. Kevin
  7. Hi. Thanks for your help. I managed to get around it using this code: var extractOrderInformation = "SELECT * FROM [order] WHERE CONVERT(NVARCHAR, orderdatetime, 103) BETWEEN CONVERT(NVARCHAR, @0, 103) AND CONVERT(NVARCHAR, @1, 103)"; Thanks again. Kev
  8. I have also tried using the convert function to no joy (to return the date value): SELECT * FROM [order] WHERE CONVERT(NVARCHAR, [orderdatetime], 101) = CONVERT(NVARCHAR, '2012-05-05', 101)
  9. Hi. I have tried the following query: SELECT * FROM [order] WHERE orderDateTime LIKE '%2012-05-04%' Unfortunately that doesn't return anything. However if I run this query: SELECT * FROM [order] WHERE orderDateTime LIKE '%2012%' It pulls back all my orders. Its as soon as I put a "-" or a "/" it just doesn't return any values. Kev
  10. Hi. Wonder if anyone can help. Am trying to retrieve records from my order table from a date inputted by the user. I've done all the SQL on my site up to here - this one is really baffling me through. Query: SELECT * FROM [order] WHERE orderDateTime LIKE '04/05/2012%'; However, it doesn't return any values - see my data types in my table below: As you can see from the data view there is data applicable in there to my query: Am at a loss. Can anyone help? Thanks. Kevin
  11. Hi. Wonder if anyone can help. I have a page (which hopefully when finished) will allow a administration user to go in and update the availability of products. I have done a query first to pull the records from the SQL database, and have then used a loop to display the records in a table: @{ Layout="~/Shared/accountArea.cshtml"; Page.Title="Update Product Availability | Sarnies For All"; if (WebSecurity.IsAuthenticated == false) { Response.Redirect("~/"); } var db = Database.Open("sarniesForAllCurrent"); var extractBread = "SELECT * FROM bread ORDER BY breadId"; if (IsPost) { var sql = "UPDATE [bread] SET available = @0 WHERE @1 = @2"; foreach(var row in db.Query(extractBread)) { } }} <h1>Update Products</h1><p>Here are all the details which we hold on our system about you. Should any of these details change please update them as necessary and click on the Update button below.</p><form method="post" action=""> <table> <tr> <th>ID</th> <th>Description</th> <th>Available</th> <th>Price</th> </tr> @foreach(var row in db.Query(extractBread)) { <tr> <td>@row.breadId</td> <td>@row.breadDescription</td> <td><input type="text" name="@row.breadId" id="@row.breadId" value="@row.available" /></td> <td align="right">£@row.price</td> </tr> } </table> <input type="submit" value="Update" /></form> I am now at a loss at how to then input any changed values back into the SQL database. I have already used the SQL update record for my "Update Profile" page as that is for one record in my user table - but am unsure of the process/code to use to update multiple records at once using the above loop method. Thanks. Kevin
  12. Again, that worked a treat, thanks for your help.
  13. I'm not really sure where to start. On my "New Order" page I have the following code: <form id="newOrder" method="post" action="processOrder.cshtml"> Then on the "processOrder.cshtml" page I tried the following: @{ Layout="~/Shared/accountArea.cshtml"; Page.Title="Process Order | Sarnies For All"; if (WebSecurity.IsAuthenticated == false) { Response.Redirect("~/"); } if (IsPost) { var breadSelection = breadSelection.Value; } } <h1>Order Status</h1><p>@breadSelection</p> I tried the above just to see if it would pull the selected value of data through to the process order page - and then tried to print it on the page. I however get the following error: Compilation ErrorDescription: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0841: Cannot use local variable 'breadSelection' before it is declaredSource Error: Line 10: if (IsPost) Line 11: {Line 12: var breadSelection = breadSelection.Value;Line 13: }Line 14: Source File: c:\sarniesForAllCurrent\processOrder.cshtml Line: 12 Managed to get this far, not quite sure how to get this to work though. Kev
  14. Hi. Quite new to ASP.NET, doing a web design course. I have built a website, and am just building the order part - this is for an assignment. This is the code I have so far: @{ Layout="~/Shared/accountArea.cshtml"; Page.Title="New Order | Sarnies For All"; if (!WebSecurity.IsAuthenticated) { Response.Redirect("~/"); } var db = Database.Open("sarniesForAllCurrent");} <h1>New Order</h1> <p>Here you can create your own sandwich. First of all select your desired bread type from the drop down box below. Then move on to select the filling which you would like in your sandwich/wrap/baguette.</p> <p>All the products shown on this page are in stock, there will be no ringing you informing you that we can't make your order! If you have any issues with this, or have a special request don't hesitate to give us a call or use the Contact Us page.</p> <form id="newOrder" method="post" action="mailto:kevin.upshaw@live.co.uk"> <h2>Choose Bread Type</h2> <fieldset class="newOrder"> <div class="panel"> @{ var extractAvailableBread = "SELECT breadId, breadDescription, price, imgReference FROM [bread] WHERE UPPER(available) = 'YES' ORDER BY breadId "; } @foreach (var row in db.Query(extractAvailableBread)) { <div class="productArea"> <div class="productTitleArea"> <p class="productTitle">@row.breadDescription</p> </div> <div class="productImageArea"> <img class="productImage" src="@row.imgReference" alt="| Sarnies For All" /> </div> <div class="productPriceArea"> <p class="productPrice">£@row.price</p> </div> <div class="productSelectionArea"> <p class="productSelection"><input type="radio" name="breadSelection" value="@row.breadDescription" /></p> </div> </div> } </div> <p class="flip">Open/Close Available Bread Selection</p> </fieldset> <h2 class="clearBreak">Choose Your Filling</h2> <fieldset class="newOrder"> <div class="panel1"> @{ var extractAvailableFilling = "SELECT fillingDescription, price, imgReference FROM [filling] WHERE UPPER(available) = 'YES' ORDER BY filling "; } @foreach (var row in db.Query(extractAvailableFilling)) { <div class="productArea"> <div class="productTitleArea"> <p class="productTitle">@row.fillingDescription</p> </div> <div class="productImageArea"> <img class="productImage" src="@row.imgReference" alt="| Sarnies For All" /> </div> <div class="productPriceArea"> <p class="productPrice">£@row.price</p> </div> <div class="productSelectionArea"> <p class="productSelection"><input type="radio" name="fillingDescription" value="@row.fillingDescription" /></p> </div> </div> } </div> <p class="flip1">Open/Close Available Fillings Selection</p> </fieldset> <h2>Choose Salad Type</h2> <fieldset class="newOrder"> <div class="panel2"> @{ var extractAvailableSalad = "SELECT saladDescription, price, imgReference FROM [salad] WHERE UPPER(available) = 'YES' ORDER BY saladId "; } @foreach (var row in db.Query(extractAvailableSalad)) { <div class="productArea"> <div class="productTitleArea"> <p class="productTitle">@row.saladDescription</p> </div> <div class="productImageArea"> <img class="productImage" src="@row.imgReference" alt="| Sarnies For All" /> </div> <div class="productPriceArea"> <p class="productPrice">£@row.price</p> </div> <div class="productSelectionArea"> <p class="productSelection"><input type="radio" name="saladDescription" value="@row.saladDescription" /></p> </div> </div> } </div> <p class="flip2">Open/Close Available Salad Selection</p> </fieldset> <h2 class="clearBreak">Confirmation</h2> <p>Please confirm your selections and then hit the "Create" order button below. Your order will then be submitted and you will be redirected to your account.</p> <input type="submit" id="submit" name="submit" value="Create Order" /> <input type="reset" id="resetOrderForm" name="resetOrderForm" value="Reset Order Form" /> </form> All the code I have works absolutely fine so far. It queries the "bread" table in the database for "available" bread. The idea I had now is that for each section the user would select one option (hence the use of radio buttons) and when the user selects the option in each section the "*Id" for the option selected is stored in a variable - in which I can then do a SQL INSERT INTO - into the order database. However everything I try code wise has failed on me and wondering if anyone has any suggestions/advice?
  15. That's brilliant, worked a treat. Cheers.
×
×
  • Create New...