i have a private sub that reads 4 lines of data from a text file, and then
uses whats read and stores them in varibles. see below
Dim FileName As String = configfileV
Dim TextFromTheFile As String ' Whole text
Dim Lines() As String ' File splitted to lines
Dim LineSeparator() As String = {Environment.NewLine} ' Line separator 'character'
' Use My namespace
If My.Computer.FileSystem.FileExists(FileName) Then
' Read the file
TextFromTheFile = My.Computer.FileSystem.ReadAllText(FileName)
' Get lines. I used StringSplitOptions that removes empty lines
Lines = TextFromTheFile.Split(LineSeparator, System.StringSplitOptions.RemoveEmptyEntries)
' Now you have Lines() array ready
ServerV = Lines(0).Substring(Lines(0).IndexOf("="c) + 1)
databaseV = Lines(1).Substring(Lines(1).IndexOf("="c) + 1)
usernameV = Lines(2).Substring(Lines(2).IndexOf("="c) + 1)
passwordV = Lines(3).Substring(Lines(3).IndexOf("="c) + 1)
Else
' The file not found error
MessageBox.Show("Config file does not exist", "File Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
If vbOK Then End
End If
' checks to see if the date format is valid, if not end the project
If IsDate(datestr) Then
Else
MsgBox("Licence Error", MsgBoxStyle.Critical, "Invalid Licence format")
End
End If
'checks the date againts the text file
'Me.txtday.Text = datestr
expiredateV = datestr
'checks the licence date agains the licence file
If Today.Date = expiredateV Then MsgBox("Renew Required In 1 Day Contact Tecnical Support")
If Today.Date > expiredateV Then Endsubscrition()
this all works fine.
i uses this varibles to build up a sql connection string.
Public ConnectionString As String = "Data Source=" & ServerV & ";Initial Catalog=" & databaseV & ";Persist Security Info=True;User ID=" & usernameV & ";Password=" & passwordV & ""
when running this code
Public Function searchname() As DataView
Dim SelectQry = "SELECT * FROM donerdetails where name Like'" & Me.txtname.Text & "%'"
Dim SampleSource As New DataSet
Dim TableView As DataView
Try
Dim SampleCommand As New SqlCommand()
Dim SampleDataAdapter = New SqlDataAdapter()
SampleCommand.CommandText = SelectQry
SampleCommand.Connection = Connection
SampleDataAdapter.SelectCommand = SampleCommand
SampleDataAdapter.Fill(SampleSource)
TableView = SampleSource.Tables(0).DefaultView
Catch ex As Exception
Throw ex
End Try
Return TableView
End Function
i get a error to say... Login failed for user ".
if i manual populate the varibles in the code like so it works fine.
Public ServerV As String = Nothing "localhost"
Public databaseV As String = Nothing "Giftaid"
Public usernameV As String = Nothing "mbish"
Public passwordV As String = Nothing "mbish"
sorry for all the code but thought it best so you can understand the full process, hope someone can help.. thanks in advance