I need to insert new records into an Access database.
I'm using Visual Studio 2008 and firstly create a asp.net website. I can connect to the information in Access databse using dataview or gridview and can query a particular entry (ie. Proposal No. -brings up all details linking to that proposal).
I can then edit the details of that proposal and this would update the Access Db.
What I need to do is to have a form that simply enters new details for a new customer.
ie. Enter name [____] Enter Adress[____]. Then for this to update the database. By using the gridview or dataview I am able to view all fields that exist in the table and edit them. Is there a way that I can get a blank gridview/dataview template (which includes all the fields in the table) and fill it out to then update the database?
Thanks
相关问题
- Carriage Return (ASCII chr 13) is missing from tex
- How to know full paths to DLL's from .csproj f
- How to store image outside of the website's ro
- Importing NuGet references through a local project
- the application was unable to start correctly 0xc0
相关文章
- asp.net HiddenField控件扩展问题
- asp.net HiddenField控件扩展问题
- Asp.Net网站无法写入错误日志,测试站点可以,正是站点不行
- asp.net mvc 重定向到vue hash字符串丢失
- FormsAuthenticationTicket expires too soon
- How to show location of errors, references to memb
- “Dynamic operations can only be performed in homog
- How to add external file to application files ( cl
The best way to go is to add a table right below your gridview, and stick the form fields into it.
Alternatively, you can put the form fields in the grid's < asp:FooterTemplate>, but you would have to duplicate them in the < EmptyDataTemplate> to see the ADD form when your grid is empty.
When user clicks the ADD button, insert the form data into the database, and rebind the grid to show the newly inserted row.
EDIT: to answer you comment, you'd have to use the < asp:TemplateFiels> in your gridview in order to put the "insert form" into the FoorterTemplate. i assume you are using < asp:BoundField> now.
Again, i recommend that you put your "insert form" in the table right below the grid.
Read this article for detailed explanation
The usual way of allowing the end user to add a new record to a database is through presenting the user with a set of controls to fill in and/or select from i.e. a number of labelled textbox, listbox, checkbox, etc. controls.
How these are laid out is up to you, and you could lay them out to mimic your gridview. I would recommend creating a user control and then using that in your page.
EDIT:
To answer your comment about how to add the fields as a record to the database, you would do something like the following (this is in C#)
Firstly, set up add a connection string to the connectionstrings section in your web.config. It is generally good practice to set them up here if you're going to be using the same data source throughout your application, as it saves you from having to write the connection string out each time
Then in the code-behind for your page
The using statements will dispose of the objects once finished with (they are essentially Try-Finally blocks).
Depending on the version of Access, it may be possible to return a value after the insert to indicate whether the insert has succeeded or not (I'm only familiar with Access 97 - 2003). If this is possible, you may want to use ExecuteScalar instead of ExecuteNonQuery to obtain the return value and respond accordingly.
As a very general piece of advice, I would not recommend Jet (the database engine that Access uses) as the backend database for an ASP.NET website- have a look at the answers to this question for reasons why. SQL Server 2005 Express is free to use* and is an excellent database choice for web development.
*There are some limitations, check Microsoft Website for details.