开发者

Visual studio asp.net sql Server insert form

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 pro开发者_JAVA百科gramming 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 DetailsView control to perform an insert. Follow these simple steps:

  1. Create a new Web Form in Visual Studio
  2. Make sure you're in Design View (and not Source View)
  3. Drag and drop a SqlDataSource onto the form (in the toolbox's Data category)
  4. Click on the little |> arrow next to the SqlDataSource's gray blob and run the Configure Data Source wizard
  5. Select the database and table and fields that you want
  6. On the last page of the wizard you can test the query to make sure it works
  7. Drag and drop a DetailsView onto the form (also in the toolbox's Data category)
  8. Click on the little |> arrow next to it and in the list of data sources choose the SqlDataSource that you just created

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.


OP here. (created an account so I hvae a diff. name.)

Your answer wasn't quite what I was looking for but it taught m3 how to use Visual Studio enough to get it done. (I didn't know there was a toolbox) Thanks again for the help:)

Also, I couldn't figure out how to reply again so this is an "answer."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜