Solved

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
8
641 Views
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?
0
Comment
Question by:dswett2
[X]
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
8 Comments
 
LVL 29

Accepted Solution

by:
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
            ObjConn.Open()
            objCmd.ExecuteNonQuery()
             ObjConn.Close()
    End Sub
0
 
LVL 18

Expert Comment

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

Expert Comment

by:QPR
ID: 20309963
Pasted (and amended) from something I was doing at the time and forgot to exclude.
0
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!

 
LVL 18

Expert Comment

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

Author Comment

by:dswett2
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?
0
 
LVL 29

Expert Comment

by:QPR
ID: 20310026
imports system.data.sqlclient

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
0
 

Author Comment

by:dswett2
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?
0
 

Author Comment

by:dswett2
ID: 20310337
n/m, I got it.

Thanks!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 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