Results 1 to 2 of 2

Thread: update sql

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2004
    Posts
    11

    update sql

    I am trying to update my SQL database. With this code it will not work if I want to pass it the text from a textbox. If I set
    Dim outgoingpath As String = TextBox1.Text
    it does not work... if I do this instead
    Dim outgoingpath As String = "test"
    it works. Is there something special I have to do to the textbox to make it work? Thanks.

    Dim PathInfo As String
    PathInfo = Request.QueryString("OutGoingPath")
    Dim strConnection As String
    Dim outgoingpath As String = TextBox1.Text
    strConnection = "data source=jwallace;initial catalog=Jt;password=testadmin;persist security info=True;user id=Julie;workstation id=Jw;"
    Dim mySelectQuery As String = "UPDATE Gateway SET OutGoingPath = '" & outgoingpath & "' WHERE OutGoingPath= '" & PathInfo & "' "
    Dim myConnection As New SqlConnection(strConnection)
    Dim myCommand As New SqlCommand(mySelectQuery, myConnection)
    myConnection.Open()
    myCommand.ExecuteNonQuery()
    myConnection.Close()

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Dimming a variable this way is like dimming a Const. You can not
    dimension a Constant with a variable value. Defeats the purpose
    of a Constant.
    VB Code:
    1. Dim outgoingpath As String = TextBox1.Text
    Just Dim the variable and in the Form_Load or Sub Main
    procedure set the value of the variable to the textbox.
    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.     Dim outgoingpath As String
    4.    
    5.     outgoingpath = TextBox1.Text
    6.     '...
    7.     '...
    8.     '...
    9.  
    10. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width