How to insert Data into database using Javascript [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have an Asp.net web application. I have to use javascript to insert data on the same local machine, where I'm already using a 3-tier architecture and Stored procedures.
My question is:
Is there a way to insert data starting from javascript ?
please explain how this can be done ?
Thanks!!

Obviously, you'll have to traverse all your tiers. You may use AJAX on the client and have an ASMX on the receiving end which actually inserts the data. Pay attention to authentication and security, attackers might send an HTTP request to the ASMX directly.
Alternatively, you'll have to post back your data through a form. Javascript does not contribute much here, in my opinion.
Now that I've read your later comments I see that it's all on your local machine.
Read about HTML5 and local storage, maybe this is what you need:
http://diveintohtml5.info/storage.html

Using ajax and webmethod you can able to insert the data.
Click here to know more

There are several ways to achieve this but my suggestion is:
In client side you can use:
JQuery methods to submit your data ($.post or $.ajax) see this link
In server side you can use:
web services that send/receive json requests see this tutorial
Remeber that with javascript the preferable way to send and receive data is using JSON data format.

Related

Is it ok to use Azure Function App to perform multiple functionalities? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 months ago.
Improve this question
I have created a Azure function with QueueTrigger. Here I am planning to perform few functionalities whenever an entry is made to Azure queue via ASP.NET Core WebAPI Controller.
public void Run([QueueTrigger(QUEUE_NAME, Connection = "StorageConnectionString")] string queueMessage)
{
_log.LogInformation($"Azure Function App call started...: {queueMessage}");
// Connect to the database and fetch the data via Stored Procedure
// Bind the data to Excel spreadsheet
// Upload the spreadsheet to Azure Blob Storage and get the filename
// Send a mail to the recepient including link to the filename
_log.LogInformation($"Azure Function App call completed...: {queueMessage}");
}
I created a separate classlibrary project which contains functionalities required for this above Azure Function App. I added reference to classlibrary project to the Azure Function App and did a validation with one functionality to send mails.
I wanted to know is it a good practice to accomplish a list of functions within a single Azure Function App or are there any other good options.
Can anyone provide their guidance regarding this scenario?
I don't think it is a good practice, I think functions should be kept simple and repeatable in case something goes wrong. You can stretch the Single-responsibility principle a bit but in this case I think you have gone too far.
Imagine the mail server is down for some reason and sending mails fail every time. Your function will be requeued and will have to fetch the data, bind the excel and upload the spreadsheet over and over just to fail again when sending the mail. There is a lot of compute and storage lost, possibly orphaned files even if you don't account for it. So I would at least split it up in two and create another trigger when the file is posted to the blob storage and let another function handle the email sending in this case. My two cents.

Best way creating a mobile app and connecting with a database [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I'm trying to find the best way creating a mobile application, and connected with a cloud database(or server).
So my first question is: Is it good practice to communicate directly into a database from a mobile app?
If yes, which is the best database for this work? Azure? Oracle? Firebase...?
If no, which is the best service to communicate first? And which protocol?
What is the most recommended way? Does it matter what os(windows?mac?) my server will use?
The best approach if to build a REST API to communicate with your server. But if you don't want to do that, you should look for Firebase. Firebase is one of the best platform to build mobile and web application really fast. It provide you with Authentication, Real-Time Database, Storage, hosting crash reports and many more. Using firebase, you can set security rules on who can write to you database thus it eliminate the risk of unauthorized access to the database.
Also keep in mind that, if you use firebase, you should structure your db in such a way that the number of read and write requests are as minimal as possible, as firebase could be a bit expensive if not used properly.
Its better to build a api in between. Doing queries in your app is kinda risky.
You could use a nodejs framework for this e.g. Sails.js or Express.js
For a cloud database, Firebase is a very easy to implement and work with Database. There are plenty of information resources about the setup and work process.

how to auto refresh div value when add/edit value in Sql table? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm using MVC 5 .net with Entity Framework.
I want to design client dashboard with list out latest data from sql database.
so how to call ajax method or refresh particular table/div value whenever any value add/edit from other source in database.
I want to call function/ajax method only when any value add/edit in database from any other source without unnecessary auto refresh using setInterval function.
please help, thanks in advance.
There are several ways of accomplishing this.
Easiest is to simply poll the data at set intervals from the server. And when it changes update. To the user this will look like changes are getting pushed out. This will also not require you to do anything special besides calling what you are already doing except in a setInteraval
You could implement websockets. This enables you to literally push data from the server to a javascript function. The support for this is pretty widespread, and there are many great tutorials for this.
Implement a framework like SignalR. This is your most complete and most bakward compatible solution. If there is support for websockets it will be used otherwise it will fall back to simple ajax calls.
Personally Id opt for option 1. unless you have some major traffic or the queries are super heavy to compute on the server. You could even implement a second API that you can call to check for updates very frequently, the second api might return an integer, if that integer is higher than last time we know there is an update and we should make the big heavy query. If this dosent work go for signalR or something similar. https://www.reddit.com/r/dotnet/comments/68rgxq/signalr_alternatives/

How to connect online DB Xamarin? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
please tell me how to retrieve a data from online database(table)?. I just created a table in enter link description here
And I made a SQL database. And can anyone tell me how to retrieve a data from that?
It is strongly advised for you to not directly connect to a database straight from Xamarin for (at the very least) 2 distinctive reasons:
1. Your credentials for the database will be in your app code, meaning anyone can just decompile your app and read your login info - huge security risk.
2. By connecting to a online database straight from Xamarin you'll most probably overload the database server (they allow only a small number of connections).
Usually when you need data from a database you work with an API that you build yourself. For example A php site, or an ASP.NET web api.
Xamarin communicates with your web site (e.g. www.yoursite.com/api/getinformation). This way your credentials are safe in the website, and your app connects only to your site, which is better because you can cache information there, preventing an overload on your site.
Reading material that will help you:
Xamarin forum link to php+mysql+Xamarin
Consuming REST-API's with

which approach is best for GET,POST using Rest API [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
i am using rest api to fetch and save the data in database using jquery or angularjs, but i want to ask you about which approach is best for doing this.
using jquery to post the data
using angularjs to post the data
using c# code behind to post the data using mvc.
performance and security wise which is best.
There is no 'best' way to do this, but I'd suggest implementing your RESTful API using ASP.NET Web API and then consuming that with AngularJS on the front-end (using the $http service). It's a pretty neat way of communicating with your APIs without having to navigate away from the page, as you would have to do if it was all implemented using ASP.NET MVC.
But then I suppose it depends what you're actually implementing, does it make sense to navigate away from a page after creating or updating something? If you're creating entities from a HTML form then it would make sense to navigate the user to a completely different page after creating/updating. But if you're doing something different like changing the order of entities in a list, consuming a RESTful API without navigating away from the page would make sense.

Categories