Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
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 August 19th, 2004, 09:05 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
Default Insert Textbox values into SQL use Parameters Simp

First time using Parameters.
Connection String correct.
SQL Table fields match with parameter.
Field datatype and length match
Sql Table permissions are all there.


I got this code from a few books but I can't get it to display "Success" only "Failed".
What is my problem???



Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        Dim myCONN As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))



Dim sSql As String = "INSERT INTO Member (FName, LName) VALUES (@FName, @LName)"

        Dim insertCmd As New SqlCommand(sSql, myCONN)
        insertCmd.Parameters.Add("@FName", SqlDbType.NVarChar, 50)
        insertCmd.Parameters.Add("@LName", SqlDbType.NVarChar, 50)

        insertCmd.Parameters("@FName").Value = txtFName.Text
        insertCmd.Parameters("@LName").Value = TxtLName.Text


        Dim bSuccess As Boolean
        bSuccess = True

        Try
            myCONN.Open()
            insertCmd.ExecuteScalar()
            myCONN.Close()

        Catch ex As Exception
            bSuccess = False
            Response.Write("Failed")
        Finally
            If myCONN.State = ConnectionState.Open Then
                myCONN.Close()
            End If
        End Try

        If bSuccess = True Then
            Response.Write("Sucess")
        End If



    End Sub

 
Old August 19th, 2004, 11:12 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Are you sure you are establishing a connection? In addition, in the catch block, add:

Response.Write(ex.ToString())

And post that to this thread.

Brian
 
Old August 19th, 2004, 02:38 PM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 245
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I added:
insertCmd.CommandType = CommandType.Text
        insertCmd.Connection = myCONN

And it works.
Thanks.




 
Old August 20th, 2004, 07:38 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

That's weird... the default is Text, so you shouldn't have to define it. And you pass in a connection... but if it works it works.

Glad to hear it.

Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
JSP code to insert values from HTML form to SQL se rbyamukama Pro JSP 3 January 29th, 2013 07:42 AM
Insert text into webpage textbox vutaviva C# 1 November 26th, 2006 08:16 PM
One textbox, Two Parameters, with Stored Procedure GailCG Classic ASP Professional 0 March 3rd, 2006 03:39 PM
Taking values from textbox derekl ASP.NET 1.0 and 1.1 Professional 3 February 20th, 2006 08:30 AM





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