I'm developing an online timesheet submission system (in ASP.NET C# 'sharp') and I want to submit all of the input data (from various controls) into an SQL server database. Nothing I have seen online deals with multiple control values into the same destination database yet. The controls are stored in cells of an HTML table (for structure). The user selects their hours worked from multiple drop down lists (items = 1-12) and the selectedItem in the Drop down's are calculated into "Total hours", Read-only textboxes. Other controls include non read-only textboxes (for user names) and other textboxes (for comments). Ideally, upon clicking "Submit My Timesheet", I want all of the information saved to an SQL database.
-
question seems little hard to understand..Jigar Pandya– Jigar Pandya2012-07-06 10:15:10 +00:00Commented Jul 6, 2012 at 10:15
-
In your button click handler you should be able to access any of the input controls on the page, load them into variables and then pass them to a database via a stored procedure (or whatever other method you are using for DB access). Where exactly is the problem?Chris– Chris2012-07-06 10:17:52 +00:00Commented Jul 6, 2012 at 10:17
-
Okay, thanks Chris. The problem is in my lack of experience I'm afraid, it's a learning curve anyway.user1506376– user15063762012-07-06 10:26:33 +00:00Commented Jul 6, 2012 at 10:26
-
Your question is not very clear (elaborate with more details). If you are after a solution for saving the asp.net control values to DB there are plenty of articles on the web (as this is very basic). Have a look at this SO discussion as well stackoverflow.com/questions/4762381/…Prashanth Thurairatnam– Prashanth Thurairatnam2012-07-06 10:27:05 +00:00Commented Jul 6, 2012 at 10:27
1 Answer
Create variable in code behind for each control whose value you want to save in data base.
Then follow the steps:: I am just mentioning the steps you can write the code I guess.
Create a database connection by using SqlConnection class.
The write your insert scrit as string. for example
sting strInsertScript = "INSERT INTO TIME_SHEET (values.....)";
then execute the command bu using ExecuteNonQuery like below
Create a database command by using SqlCommand class.
SqlCommand objCommand = new SqlCommand(strInsertScript);
objCommand.ExecuteNonQuery();
Now your data is saved in database.