Results 1 to 4 of 4

Thread: Using Textbox.Text in Connection String VB.NET 2008

Threaded View

  1. #1

    Thread Starter
    Addicted Member condonethis's Avatar
    Join Date
    Apr 2010
    Location
    TX
    Posts
    133

    Question Using Textbox.Text in Connection String VB.NET 2008

    Using the following code and trying to allow the end user to specify the values for the connection string for an app that inports .csv to a specified location. App fails to run due to the fact that it tries to initialize connection string on program run resulting in NULL values. Is there any way I can prevent this and make this work?

    vb.net Code:
    1. Imports System.Data.SqlClient
    2. Imports System.IO
    3. Imports System.Configuration
    4. Imports System.Data.Common.DbConnection
    5.  
    6. Public Class csvUpdate
    7.  
    8.     'connection string
    9.     Public WithEvents con As New SqlConnection _
    10.  ("Data Source=" + TxtServer.Text + ";Initial Catalog=" + TxtCat.Text + ";Integrated Security=True;Asynchronous Processing=True")
    11.  
    12.     Public WithEvents var As New SqlConnection _
    13.    ("Data Source=" + TxtServer.Text + ";Initial Catalog=" + TxtCat.Text + ";User Id =" + TxtUser.Text + ";Password=" + TxtPass.Text + ";Asynchronous Processing=True")
    14.  
    15.  
    16.  
    17.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    18.         Me.Height = 172
    19.     End Sub
    20.  
    21.    
    22.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCSV.Click
    23.         If TxtTable.Text <> "" Then
    24.             OpenFileDialog1.Title = "Open a Text File"
    25.             OpenFileDialog1.Filter = "Comma Delimited(*.csv)|*.csv"
    26.             OpenFileDialog1.DefaultExt = ".csv"
    27.             OpenFileDialog1.InitialDirectory = "C:\"
    28.             OpenFileDialog1.ShowDialog()
    29.             If ChkAD.Checked = True Then
    30.                 'readcsvAD()
    31.             Else
    32.                 'readcsvUP()
    33.             End If
    34.         Else
    35.             TxtTable.Focus()
    36.         End If
    37.     End Sub
    38.  
    39.     Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChkAD.CheckedChanged
    40.  
    41.         If Me.Height < 242 Then
    42.             Me.Height = 243
    43.         Else
    44.             Me.Width = 144
    45.             Me.Height = 172
    46.         End If
    47.  
    48.     End Sub
    49. End Class


    Thanks!
    Attached Files Attached Files

Tags for this Thread

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