I have to do this thing for work that’s really just a formality. Normally I’m a linux/UNIX guy but they’re making me do this. I need to have an asp webpage that displays data from two different database servers. This is easy — just a drag and drop in visual studio. The problem is I also need a way to insert a new row into a table on the SQL Server 2008 database. Right now I have:
<html><body>
...
<asp...
stuff to display data
...>
...
<form>
Name: <input type="text" name="name" id="name" /><br>
Quantity: <input type="text" name="quantity" id="quantity" /><br>
<input type="submit" />
</form>
</body></html>
I know html quite well and I’ve also done quite a bit of web programming in python that uses MySQL in the backend but I can’t stand programming with a GUI. I know how to do the connection string I just don’t know how to make asp.net see the data in the fields.
Oh and the table is a simple two column table: one varchar for a product’s name and an int for its quantity. All this has to be done in visual studio.
In Visual Studio for an ASP.NET page you can use the
DetailsViewcontrol to perform an insert. Follow these simple steps:SqlDataSourceonto the form (in the toolbox’s Data category)DetailsViewonto the form (also in the toolbox’s Data category)Now you’re done!
Regarding your sample about raw HTML – that’s generally not the recommended approach when using ASP.NET Web Forms. With Web Forms there are rich “server controls” that worry about most of the HTML rendering for you. They also have logic in them to help make a site more secure such as HTML encoding values.