I want to take the data from my json file, parse and send to my database. Each field in my json objects have to go to it's corresponding column in my table. I don't have SQL Server 2016 so I need to do this in my ASP.NET Webpages site using razor. I was able to get the file data and I used Json.Decode to make it a object I guess?? Here is how I got the JSON file data
#{
Layout = "~/_SiteLayout.cshtml";
var json =File.ReadAllText(Server.MapPath("~/App_Data/enforcement_actions.json"));
var data = Json.Decode(json);
}
I am completely lost from this point as far as now taking the 'data' variable, parse, and send to my database file. Any help would be great.
Look for Entity Framework and mdf file here: Entity Framework on .mdf file
After that, you have to look to how to map classes on Entity Framework. You see that here: How to map an Entity framework model to a table name dynamically
And finally you'll save your data on the database. You can see it here: Insert data using Entity Framework model
Related
I have an ASP.NET solution that consist of two different projects:
Project One is the ASP.NET pages, javascript and CSS. Project Two is an encapsulated DLL that is reference by project One, and have all the logic for database Accessing.
Basically, project One collect data and creates instances of classes defined on project Two, and call method on those classes that fisically access de database (inside Project Two code) and return object of type List of(ObjectType)
Now I need to send a copy of the project One to a third party programmer, but i don't want to send Databases, so my idea is to create a copy of project Two (a new DLL), that simulates database access but insted of get data from the database returns fixed data (hardcoded) in the exact same format.
So my question is: How can I Hardcode that data on the DLL without having to create object manualy one by one?.
My first attemp is to serialize an object already returned by a database to XML with this code:
Dim sw As New System.IO.StringWriter
Dim ser As New System.Xml.Serialization.XmlSerializer(GetType(List(Of User)))
ser.Serialize(sw, Users)
Debug.WriteLine(sw.ToString)
That creates an string with all the data. But it is possible to re-create the collection from this result? Is there a better way to do this? thanks!!!
I am a newbiew to aspn.et.My requirement is to create a simple class and web form. the data submitted to the form should be stored in object of the class and then it should be saved in the sql server database.Same way the retireval. thanks.
class Student
{
int rollno;String name;int age;//default getters and settters
}
//web form has 3 text boxes for the above data fields.
//DB has a single table with these 3 fields
You can try the tutorials on asp.net, which covers pretty much all of the web technologies used/integrated with Visual Studio product. Here is the link to the WebForms with Entity Framework that will walk you through how to do it.
http://www.asp.net/web-forms/tutorials/data-access/model-binding/retrieving-data
edit: Database first method -> http://www.asp.net/web-forms/tutorials/getting-started-with-ef/the-entity-framework-and-aspnet-getting-started-part-1
Additionally, if that tutorial doesn't suit your fancy, try this search: https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=web-forms+database+first
I was trying to implement a LINQ 2 SQL implementation to one of my page to load the data to a datagrid.The below is the code
using (NorthwindDataContext context = new NorthwindDataContext())
{
var customers =from c in context.Customers select c; // Line 1
gridViewCustomers.DataSource = customers;
gridViewCustomers.DataBind();
}
I put a break point in the Line 1 to examine what type is being loaded into customer .But i couldn't see anything there.
What type this customer is of ?
I wanted to put the code to fetch data from Tables in my data access layer which is a seperate classlibrary and would like to call it from UI.What should be the return type of my method in Data access layer ? I already have a another class library which holds buisness objects/entities (Ex: Student).I was using this with Normal ADO.NET stuff before using the LINQ 2SQL stuff.How can i make it work altogether .Kindly advice
You need a LinqDataSource or ObjectDataSource to bind the Linq query to the GridView.
See here and here for examples.
i'm a total newbie with asp.net mvc and here's my jam:
i have a 3 level list box which selection on box A shows options on box B and selection on box B will show the options for box C.
I'm trying to do the whole thing in asp.net MVC and what i see is that the nerd dinner tutorial uses the ORM method.
so i created a dbml to the database and drag the stored proc inside.
i create a datacontext object but i don't quite know how to connect the result from the stored proce which should be multiple rows of data and make it into a json.
so i can keep all the json data inside the html page and using jquery i could make the selection process faster.
i don't expect the data inside the three boxes to change so often thus i think this method should be quite viable.
Questions:
So how do i get the stored proc part
to return the data as json?
i've noticed some tutorial online
that the json return result part is
at the controller and not at the
model end.
Why is that?
Edit
FYI, i find what i mostly wanted to do here.
For the json part, i referenced here.
Return a JsonResult from your controller action. You may need to coerce the result from your stored procedure into a C# class serializable to Json.
Json conversion should be done in the controller because it's not really part of the domain. More a DTO in the MVVM (Model-View-ViewModel) style.
I have a block of XML in a database which is easy enough to pull out using ASP.NET MVC, however I would like to access and modify the XML in an way more consistent with class instances. Is there a way to get the MVC (or any other model) to generate a data access (or perhaps Entity) class set from the DB-stored XML?
If the above is rather obtuse, the question could be summarised as; What method would you use to best access and modify XML stored in a database from an ASP.NET MVC application?
The method I went with in the end was simply to use LINQ2SQL to get the data from the SQL2005 DB and then pass the field value into XElement.Parse() to get an XML object I can easily work with. Manipulating the XML was the done using the information gained from helpful overflowers here:
How do I insert an element into XML using Linq?
How to add attributes to an element using LINQ, C#?
How to sort XML in LINQ C# by an attribute value? Also MVC