Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 October 24th, 2007, 02:41 AM
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm still having problems with this.

Here is the vb code for the button click:

Code:
        Dim strConnection As String
        strConnection = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("FSPConnectionString").ConnectionString
        strConnection = "Data source=(192.168.1.101);database=tharFSP;User ID=sa;Password=tharSQL"
        Dim MyConnection As SqlConnection

        MyConnection = New SqlConnection(strConnection)

        Dim cmdTest As New SqlDataAdapter("dbo.thar_HIP_importcusts", strConnection)

        cmdTest.SelectCommand.CommandType = Data.CommandType.StoredProcedure

        cmdTest.SelectCommand.Parameters.Add(New SqlParameter("@custcode_old", Data.SqlDbType.VarChar, 10))
        cmdTest.SelectCommand.Parameters("@custcode_old").Value = DDL_Import.SelectedValue

        cmdTest.SelectCommand.Parameters.Add(New SqlParameter("@custcode_new", Data.SqlDbType.VarChar, 10))
        cmdTest.SelectCommand.Parameters("@custcode_new").Value = DDL_CurrentCustomer.SelectedValue

        MyConnection.Open()


        If MyConnection.State = ConnectionState.Open Then
            cmdTest.SelectCommand.ExecuteReader()
            MyConnection.Close()
        Else
            MyConnection.Open()
            cmdTest.SelectCommand.ExecuteReader()
            MyConnection.Close()
        End If
    End Sub


I appreciate everyone's efforts.

 
Old October 24th, 2007, 03:25 AM
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oh and I tried it with reader, but have had no luck.

 
Old October 24th, 2007, 05:17 AM
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have attached an imadge with the InvalidOperationException in detail:

http://server6.theimagehosting.com/i...=error.5de.jpg


 
Old October 24th, 2007, 05:54 AM
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

YESSSSS!!!!!!!!

I got it working, after much pain!

Code:
        Dim sConnStr As String = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("FSPConnectionString").ConnectionString
        Dim cnBKTest As New SqlConnection(sConnStr)
        Dim cmdTest As New SqlCommand("dbo.thar_HIP_importcusts", cnBKTest)

        cmdTest.CommandType = Data.CommandType.StoredProcedure

        cmdTest.Parameters.Add(New SqlParameter("@custcode_old", Data.SqlDbType.VarChar, 10))
        cmdTest.Parameters("@custcode_old").Value = DDL_Import.SelectedValue

        cmdTest.Parameters.Add(New SqlParameter("@custcode_new", Data.SqlDbType.VarChar, 10))
        cmdTest.Parameters("@custcode_new").Value = DDL_CurrentCustomer.SelectedValue

        cnBKTest.Open()
        cmdTest.ExecuteNonQuery()
        cnBKTest.Close()
Sorry the variable names changed, found it on a tutorial, so just copied it. still not too sure why it didnt work before, but I don't care! :D

Thanks everybody for your efforts, really appreciate them.

 
Old October 24th, 2007, 07:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

to clarify why your first code didn't work, it was because you were not passing a connection to the command, you were passing a conection string!

look at this:
Code:
Dim strConnection As String
        strConnection = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("FSPConnectionString").ConnectionString
        strConnection = "Data source=(192.168.1.101);database=tharFSP;User ID=sa;Password=tharSQL"
        Dim MyConnection As SqlConnection

        MyConnection = New SqlConnection(strConnection)

        Dim cmdTest As New SqlDataAdapter("dbo.thar_HIP_importcusts", strConnection)


in your second try, you pass the rigth connection object to the command ;)

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old October 24th, 2007, 07:43 AM
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Goddammit, so I was!

Glad someone spotted it, I thought I was going crazy!

 
Old October 24th, 2007, 10:41 AM
Authorized User
 
Join Date: Aug 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Right. The page works fine, when I run it through VWD.

The item is designed to be ran from within an application. When it is ran through said application, It starts off fine, but after a bit, when you select an item, change a dropdown, or anything that refreshes the page, it reports the following error:

The gateway has lost the connection with the Web site you are trying to access.

I cant replicate this in debug mode, so don't know where to start in resolving this. :(






Similar Threads
Thread Thread Starter Forum Replies Last Post
Browser close when screen saver close Rehanrana Pro VB 6 1 April 7th, 2008 03:09 AM
Text Import- How to import the first 5 lines. nickzhang.zn Excel VBA 1 August 4th, 2007 05:06 PM
window.close() failing to...well...close! mheathcote Javascript How-To 2 October 31st, 2005 03:02 PM
Another Feature Request Imar Forum and Wrox.com Feedback 0 September 10th, 2003 01:57 PM
Feature Request Imar Forum and Wrox.com Feedback 9 September 2nd, 2003 08:24 AM





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