Inserting data from a asp.net web application to SQL Server - c#

I am currently trying to create a project in ASP.NET to create a stock input web application for a cafe which allows users to input stock data from web. I want to know how to save data from browser to SQL Server.
Screenshot of my current table design / ERD
The Item table will hold all information about each item. Stock_Take_Item table will hold the quantity of each item for a stock take, and Stock_Take table will hold the date of the stock take.
I want to be able to present the user with three columns, One for item description (which will already contain the item descriptions in), the second column for Bar Quantity and able the user to input this value and the third Column for Storage Quantity and also allow the user to input this value.
Once a user has filled out the columns for the stock take, will then press a submit button which will trigger c# code to insert these values into the SQL Database.
I hope this isn't too long winded and someone can give me a good recommendation on how to do so. I fully understand my tables may be wrong, and am open to changing them.

This is not actually a question of the specific problem. you rather need to read a very basic tutorial of ASP.net application.
For your convenience, I suggest you to read This Basic Example which exactly does what you need and just the table name and field names differ. I suggest you read this up first and then come here for very specific questions.

Related

ASP.net Schedule Post like Facebook

Im trying to do something similar to the Scheduling of posts for Facebook pages... on ASP.net/c#
So basically what i need is :
User fills a few text boxes
Selects a date...
The post gets posted on that date...
I am unable to really understand the logic as well as coding for this...
What i have thought so far is, once the user submits the post, store the details in a table in SQL like SheduledPosts, and when the CurrentDate(Server Date) matches the date....
Transfer the SQL entry from there to the actual PostTable.
Now the actual process needs to take place without any pages loading or any actions done by the user... So I also dont understand how to make it happen from the server side...
Please note that im not trying to post anything to facebook... rather, trying to do a schedule form submitting on my own asp.net website...
Any help regarding the logic, coding, scheduling will be greatly appriciated...
Thank You
I can think of a couple of different ways to accomplish this:
Implement a "pending posts" table and have a separate process running on the server to take care of transferring the post from the "pending posts" table to the "current posts" table at the appropriate time.
Add a "publish_on" datetime field to your current posts table, and when selecting items to be displayed in the page output, add a "WHERE publish_on IS NULL OR publish_on > GETDATE()" clause to your query. You fill this in for posts you don't want going live until a particular time.
Personally, I would go with the second approach, since I think it's a more elegant solution.
You can do this with one table. Just have a 'Submitted' date field (for your records), a 'Publish' date field and a Boolean 'Published' field. Create a Windows Service to run every 5 minutes or so and let the service perform the date check; when it finds one that satisfies the date criteria, it just toggles the Boolean field to 'true' and your page logic can then display the post.
Here is a walk-through on creating a simple Windows Service:
https://msdn.microsoft.com/en-us/library/zt39148a%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

Create a page in C# for editing data in SQL Server

I am trying to create a page in C# for editing data in SQL Server, and the data is like title, date, description and that's not a big deal
The problem is each row of this has a foreign key to another table that has image URL so each row has like 3 OR more images.
Like I said before I want to create a page which can edit all of these, I made it with listview but it really really bad so I was trying to find another ideas so can you help me in that
Well, the foreign key isn't that difficult to deal with. When a user edits that FK, before you allow the change to be committed to the cell or saved, run a check against the Db to see if their entry is valid. If it is, allow the edit, if not, cancel their edit of that value.
If that other table is the only table that has a FK to worry about, you could return just the Ids in your initial call and check against the dataset to save some round trips.

How to store history answer data in sql database?

I have a system whereby it can set the open and close dates allowing user to go in and submit answer for survey. The system also wants to delete the most current records from the database.
Example:
Person A:
1st survey: submitted on JAN/2011
2nd survey: submitted on MAR/2012
3rd, 4th...
How can i make sure that data are stored securely and able to retrieve past records and still able to delete latest?
I am thinking of storing latest data on one database and the history data on another database where it could be permanent. But then if records continue to be submitted, will it affect the search if there are more and more data stored? Any suggestion please? Heard about sql08 auditing? does it work?
Why would you want to store them in separate databases, and why would the history be any different than the latest? Just store all their answers for all time.
For the most simple example, if it's a single table for a survey, just store their user id, a unique survey id, and the date that it was submitted. When you want to get the most recent, get the Top 1 sorted by the submit date in descending order.

Entering data into a table from a login form

My doubt is pretty simple, I suppose. But still I need assistance.
I have a registration form as ASP.NET web form. There are 5-6 fields in it (username, password, email id, sex, country etc. ). I want to enter all the data, entered by a new user in the specified field, to enter the table of a database automatically, when I hit a SUBMIT button. Those data should come into sperate columnsof the table, for each field of web-form.(langauage used C#)
String Connection and then Stored Procedure could help.
Thanks in advance.
You should be using the CreateUserWizard to handle your registration. You can customise it in many many ways and it works with the rest of the asp.net membership system.
One of the ways that you can extend this control is to add extra pages to the sign up wizard that contain your own form fields and then save these to the database.
There is a great article series that will pretty much make you an expert on asp.net membership over the 4guysfromrolla site. Part 18 of this series shows how to add extra member details and store them in a database and as requested, full SQL code is included in the article.
Read part 18 here:
https://web.archive.org/web/20211020114106/https://www.4guysfromrolla.com/articles/110310-1.aspx
If you peruse the table of contents for this series I'm sure more than a couple of the other articles will catch your eye :)

dynamic column to sql table via .net OR dynamic report field

Scenario: Client maintains financial/compliance record in a spreadsheet for each quarter of the year. Spreadsheet contains columns which are not static, they can change from quarter to quarter and will not be same the next year. They want a portal by which all the regional managers (of stores/franchise) can enter their data and at the end aggregated at the national level.
Issue: As you could have guessed, I want to develop the spreadsheet column into sql table with all the columns, but the issue is that they want to add new columns dynamically (for future quarters) via admin side. Thinking of providing a textbox (columnname), dropdown (sqltypes possible) and add button which will basically add the column. But the columns can grow and that's not the right option, I guess. Other alternative is, instead of adding columns, I can add it as rows and then use PIVOT to do the sql part.
If anyone of you have developed this kind of application, could you please aware me of any complications before I proceed further with my idea of adding rows instead of columns for adding fields for the reports dynamically. If anyone has got sample example or reference online, please divert me there.
Take a look at Umbraco. It's a cms that puts the concept of PIVOT into practice. (Actually I believe most CMS does).
Actually, I'd go so far as to suggest building that application of yours in Umbraco. You will need to customise it a bit, but you will have quite a bit of heavy lifting already done for you, such as authorisation, membership, and the schema/content mechanism.

Categories

Resources