Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

Patulong mga master sa VB.NET

cyber6580

Apprentice
Advanced Member
Messages
56
Reaction score
0
Points
26
Patulong naman po sa magagaling sa VB.Net basic lng alam ko and self study lang. Meron ksi ako ginawang simple program para makapagscan ng barcode. Working naman for more than 1 year na. Ang problem ko lang is pag nagpapalit sila ng server need ko update ung connection string nya sa source code kasi hardcoded dun yung db access credentials. Naisip ko gumawa ulit ng isang apps para dun i enter ung db credential, yung mga value na ininput dun ang kukunin ni main application para sa connection nya sa database. Pano kaya gagawin un?

View attachment 337920
 

Attachments

  • Doc1.jpg
    Doc1.jpg
    84.9 KB · Views: 28
Patulong naman po sa magagaling sa VB.Net basic lng alam ko and self study lang. Meron ksi ako ginawang simple program para makapagscan ng barcode. Working naman for more than 1 year na. Ang problem ko lang is pag nagpapalit sila ng server need ko update ung connection string nya sa source code kasi hardcoded dun yung db access credentials. Naisip ko gumawa ulit ng isang apps para dun i enter ung db credential, yung mga value na ininput dun ang kukunin ni main application para sa connection nya sa database. Pano kaya gagawin un?

View attachment 1246661
Boss mas maganda cguro if gsto mung e save yung database parameter gumamit ka ng textfile dun mu e save yung database. pra kng nasa iban PC ka no need to open ng program but only edit mu lg yung textfile.

First Option===>
Code:
 Dim FILE_NAME As String = Application.StartupPath & "\config.txt"
        Dim i As Integer
        Dim aryText(4) As String

        aryText(0) = TextBox1.Text
        aryText(1) = TextBox2.Text
        aryText(2) = TextBox3.Text
        aryText(3) = txtdb.Text


        Dim objWriter As New System.IO.StreamWriter(FILE_NAME)

        For i = 0 To 4

            objWriter.WriteLine(aryText(i))

        Next

        objWriter.Close()

        MessageBox.Show("In order to apply changes we need to restart application!", "Restart Application?", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)


        Application.Restart()



Second Option:

Code:
Public server As String
    Public Serveruser As String
    Public password As String
    Public dbname As String

    Public Sub setCOnfig()
        Dim FILE_NAME As String = Application.StartupPath & "\config.txt"

        If System.IO.File.Exists(FILE_NAME) = True Then

            Dim objReader As New System.IO.StreamReader(FILE_NAME)

            server = objReader.ReadLine()
            Serveruser = objReader.ReadLine() & vbNewLine
            password = objReader.ReadLine() & vbNewLine & vbNewLine
            dbname = objReader.ReadLine() & vbNewLine & vbNewLine & vbNewLine


        Else

            MsgBox("Config File Does Not Exist!")

        End If
    End Sub
    Public Function myconn() As MySqlConnection
        setCOnfig()
        Return New MySqlConnection("server=" & server & ";user id=" & Serveruser & ";password=" & password & ";database=" & dbname & "")
    End Function

Bali it yung yung laman ng textfile
View attachment 337945
 

Attachments

  • txtfile.png
    txtfile.png
    4.9 KB · Views: 2
Boss mas maganda cguro if gsto mung e save yung database parameter gumamit ka ng textfile dun mu e save yung database. pra kng nasa iban PC ka no need to open ng program but only edit mu lg yung textfile.

First Option===>
Code:
 Dim FILE_NAME As String = Application.StartupPath & "\config.txt"
        Dim i As Integer
        Dim aryText(4) As String

        aryText(0) = TextBox1.Text
        aryText(1) = TextBox2.Text
        aryText(2) = TextBox3.Text
        aryText(3) = txtdb.Text


        Dim objWriter As New System.IO.StreamWriter(FILE_NAME)

        For i = 0 To 4

            objWriter.WriteLine(aryText(i))

        Next

        objWriter.Close()

        MessageBox.Show("In order to apply changes we need to restart application!", "Restart Application?", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)


        Application.Restart()



Second Option:

Code:
Public server As String
    Public Serveruser As String
    Public password As String
    Public dbname As String

    Public Sub setCOnfig()
        Dim FILE_NAME As String = Application.StartupPath & "\config.txt"

        If System.IO.File.Exists(FILE_NAME) = True Then

            Dim objReader As New System.IO.StreamReader(FILE_NAME)

            server = objReader.ReadLine()
            Serveruser = objReader.ReadLine() & vbNewLine
            password = objReader.ReadLine() & vbNewLine & vbNewLine
            dbname = objReader.ReadLine() & vbNewLine & vbNewLine & vbNewLine


        Else

            MsgBox("Config File Does Not Exist!")

        End If
    End Sub
    Public Function myconn() As MySqlConnection
        setCOnfig()
        Return New MySqlConnection("server=" & server & ";user id=" & Serveruser & ";password=" & password & ";database=" & dbname & "")
    End Function

Bali it yung yung laman ng textfile
View attachment 1246689

Thanks sir try ko to.
 
Pwede din sa Application configuration file.
dun mo na lang ieedit para di mo na irecompile ung system. eedit mo na lang sya sa notepad.
mag lagay ka lang ng Application Configuration file sa project mo:

example: ganito itsura nung loob ng App.Config
sa loob ng configuration tag gawa ka ng new tag which is AppSettings if di pa existing
sa pagitan ng appsettings tag lagay mo ung line na <add key ... etc.
gayahin mo lang at palitan ng value

Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <appSettings>
      <add key="ConnectionString"
           value="Server=localhost;Database=Northwind;Integrated
                  Security=false;User Id=sa;Password=;" />
   </appSettings>
</configuration>


Pano i-access sa code? ganito
Code:
Dim connString As String = ConfigurationManager.AppSettings("ConnectionString")
 
Pwede din sa Application configuration file.
dun mo na lang ieedit para di mo na irecompile ung system. eedit mo na lang sya sa notepad.
mag lagay ka lang ng Application Configuration file sa project mo:

example: ganito itsura nung loob ng App.Config
sa loob ng configuration tag gawa ka ng new tag which is AppSettings if di pa existing
sa pagitan ng appsettings tag lagay mo ung line na <add key ... etc.
gayahin mo lang at palitan ng value

Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <appSettings>
      <add key="ConnectionString"
           value="Server=localhost;Database=Northwind;Integrated
                  Security=false;User Id=sa;Password=;" />
   </appSettings>
</configuration>


Pano i-access sa code? ganito
Code:
Dim connString As String = ConfigurationManager.AppSettings("ConnectionString")

meron ako App.config boss sa project ko. Ganyan pala gagawin, kasi yung nsa code ko nilagay ko parin ung database credentials kaya dami ko binabago. Malaking tulong to. Thanks.
 
Back
Top Bottom