Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 23rd, 2005, 02:42 PM
Authorized User
 
Join Date: Aug 2005
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default Posting a form to a database

Hello all,

Does anyone know how to add the values of a submitted form to a Microsoft Access Database?

Thanks for any help

Ray

 
Old September 25th, 2005, 09:46 AM
Authorized User
 
Join Date: Aug 2005
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hope this helps http://msdn.microsoft.com/library/de...qldatabase.asp

 
Old September 26th, 2005, 10:38 AM
Authorized User
 
Join Date: Aug 2005
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Lofa,

Do you know another place where I can get an example. That one looked a bit complicated. This is what I am understanding. Please let me know if you simplyfy it for me.

thanks,

Ray


Dim myCommand As SqlCommand
Dim insertCmd As String

insertCmd = "insert into Authors values (@FName);"

myCommand = New SqlCommand(insertCmd, myConnection)

myCommand.Parameters.Add(New SqlParameter("@FName", SqlDbType.VarChar, 20))

myCommand.Parameters("@FName").Value = au_fname.Value

 
Old September 26th, 2005, 01:11 PM
Authorized User
 
Join Date: Aug 2005
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is how you work with storedProcedure in SQL Server
CREATE PROCEDURE AdminUser_Insert

    @retval int OUTPUT,
     @UserID varchar(50),
        @Password varchar(32),
        @First_Name varchar(32),
        @Last_Name varchar(32)

AS
    INSERT INTO users
    (
    UserID,
    Password,
    First_Name,
    Last_Name
    )
    VALUES
    (
    @UserID,
    @Password,
    @First_Name,
    @Last_Name
    )

    SET @retval = @@IDENTITY
GO

Then in your code do the following:

             Dim loConn as New SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))
             Dim AccountID As Integer
             Dim cmdInsert as New SQLCommand("AdminUser_Insert", loConn)
             cmdInsert.CommandType = CommandType.StoredProcedure
             cmdInsert.Parameters.Add(New SqlParameter("@retval", SqlDbType.int))
             cmdInsert.Parameters("@retval").Direction = ParameterDirection.Output
             cmdInsert.Parameters.Add(New SqlParameter("@UserID", SqlDbType.varchar, 50, "UserID"))
             cmdInsert.Parameters("@UserID").Value = Request("UserID")
             cmdInsert.Parameters.Add(New SqlParameter("@Password", SqlDbType.varchar, 32, "Password"))
             cmdInsert.Parameters("@Password").Value = Request("Password")
             cmdInsert.Parameters.Add(New SqlParameter("@First_Name", SqlDbType.varchar, 32, "First_Name"))
             cmdInsert.Parameters("@First_Name").Value = Request("FirstName")
             cmdInsert.Parameters.Add(New SqlParameter("@Last_Name", SqlDbType.varchar, 32, "Last_Name"))
             cmdInsert.Parameters("@Last_Name").Value = Request("LastName")
             loConn.Open()
             cmdInsert.ExecuteNonQuery()
             loConn.Close()
             AccountID = cmdInsert.Parameters("@retval").Value





 
Old September 27th, 2005, 08:39 AM
Authorized User
 
Join Date: Aug 2005
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Lofa,

Thank you for your help. I am a bit new to this and appreciate your help. I am using an Access Database. So to make the above code work. Would I change this line:

Dim loConn as New SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))
to
Dim loConn as New OleDbConnection(ConfigurationSettings.AppSettings( "ConnectionString"))

and:

Dim cmdInsert as New SQLCommand("AdminUser_Insert", loConn)
to
Dim cmdInsert as New OleDbCommand("AdminUser_Insert", loConn)

Is there anything else I need to change for this to work?

thanks,

Ray

 
Old September 28th, 2005, 05:29 AM
Authorized User
 
Join Date: Aug 2005
Posts: 68
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is a code that I copied from www.asp.net
There is also a good forum
And here is a page about stored procedures in access http://authors.aspalliance.com/hrmal.../20030301.aspx
I'm also a new using this. Most of my codes are done with Dreamweaver. And then used google and asp.net forum and this forum
Sub add_btn_Click(sender As System.Object, e As System.EventArgs)


    Dim intRecordsInserted As Integer


    Dim sText As String


    sText=fname.text


    Dim connstr As String


    connstr = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\inetpub\wwwroot\webform.mdb"


    Dim SQL As String = "INSERT INTO users2 (fname) VALUES ('" & sText & "')"


    Dim Conn As New OleDbConnection(connstr)


    Dim cmd As New OleDbCommand(SQL, Conn)


Try


Conn.Open()


    intRecordsInserted = cmd.ExecuteNonQuery()


    label.Text = intRecordsInserted & " record(s) added successfully."


Catch ex As Exception


    label.text = "An error has occurred: "


    label.text += ex.Message


Finally


    Conn.Close()


End Try


End Sub








Similar Threads
Thread Thread Starter Forum Replies Last Post
Textarea form posting Apocolypse2005 HTML Code Clinic 2 April 20th, 2007 03:59 PM
AJAX form posting problem. NisarAhamed Ajax 0 November 21st, 2006 01:09 AM
Posting the value of an unbound form field into a ebburks Access 8 May 27th, 2006 04:38 PM
Posting from a form to a access database rayncarnation ASP.NET 1.0 and 1.1 Basics 0 September 2nd, 2005 10:18 AM
Losing form variables (from posting) BunaZiua Dreamweaver (all versions) 1 February 23rd, 2004 04:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.