How do I create a custom input form to insert data into a database with Visual Web Developer? (ASP.NET)

Posted on 2007-11-18
Last Modified: 2011-03-21
I want to create a custom form layout to insert data into a database using ASP.NET. I can insert data using the DetailsView tool, but I want the data to be laid out in a custom way (not a table) and I don't really want my users to have to click "Insert" to have the fields appear (which DataView requires). Can I do this by editing a template in one of the views or input box by input box? What is the best way of going about this?
Question by:dswett2
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
LVL 29

Accepted Solution

QPR earned 500 total points
ID: 20309952
input box by input box
then an asp:button

Double click the button (in design view) and do something like....

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Page.IsValid Then
            Dim connectionstring As String = System.Configuration.ConfigurationManager.ConnectionStrings("MyConnectionString").ConnectionString
            Dim ObjConn As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionstring)
            Dim objCmd As SqlCommand = New SqlCommand()
            objCmd.Connection = ObjConn
            Dim name As String = txtName.text
            Dim address As String = txtAddress.Text
            objCmd.CommandType = System.Data.CommandType.StoredProcedure
            objCmd.CommandText = "dbo.InsertNewPerson"
            objCmd.Parameters.Add("@name", Data.SqlDbType.VarChar).Value = name
            objCmd.Parameters.Add("@address", Data.SqlDbType.VarChar).Value = address
    End Sub
LVL 18

Expert Comment

ID: 20309957
Just inquisitve about the use of  Page.IsValid. Any reasons?
LVL 29

Expert Comment

ID: 20309963
Pasted (and amended) from something I was doing at the time and forgot to exclude.
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

LVL 18

Expert Comment

ID: 20309976
Ok. I thought it had some relevance. Learnig process should be on - that's why I asked :-) Thanks.

Author Comment

ID: 20310019
QPR, Is there an import statement that needs to go at the beginning? I get Type 'SqlCommand' is not defined.

Also, where is the INSERT SQL statement in this solution?
LVL 29

Expert Comment

ID: 20310026

InsertNewPerson is the name of a stored procedure that excepts 2 (varchar) parameters name and address.
You could alter the code to use a select statement instead of a SP

Author Comment

ID: 20310041
When I run it, I get a

Could not find stored procedure 'dbo.InsertNewPerson'.

What would the code be if I just wanted to use sql statements? What are the advantages of SPs?

Author Comment

ID: 20310337
n/m, I got it.


Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question