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
637 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
Comment Utility
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
Comment Utility
Just inquisitve about the use of  Page.IsValid. Any reasons?
0
 
LVL 29

Expert Comment

by:QPR
Comment Utility
Pasted (and amended) from something I was doing at the time and forgot to exclude.
0
 
LVL 18

Expert Comment

by:Sethi
Comment Utility
Ok. I thought it had some relevance. Learnig process should be on - that's why I asked :-) Thanks.
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:dswett2
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
n/m, I got it.

Thanks!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now