0

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.

4
  • question seems little hard to understand.. Commented 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? Commented 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. Commented 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/… Commented Jul 6, 2012 at 10:27

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

6 Comments

This is terrible advice. At the very least you should not recommend constructing the SQL string manually rather than using a parametrized query. Better would suggest using an ORM given how easy they are to configure and how much work they take out of manually maintaining SQL.
Now I'm getting this: Column name or number of supplied values does not match table definition.Exception Details: System.Data.SqlClient.SqlException: Column name or number of supplied values does not match table definition. Source Error:
Please let me know the table schema and the insert script you have written. Then I can tell why you are getting this exception. Check if you have mentioned the column names properly in the insert script.
@R01MANARMY: I know when to use parametrized, I think the guy is just learning basics, so first let him do the task in simple way, then he can work on higher stuff.
@user1506376: Also replace single quote in your input data as double quote. Because single quote will break your script.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.