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
639 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

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 …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

778 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