VS 2013 SQL Connection string to ODBC (DSN) Connection String-VBForums
Results 1 to 2 of 2

Thread: SQL Connection string to ODBC (DSN) Connection String

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2010

    SQL Connection string to ODBC (DSN) Connection String


    I created a project in vb.net and SQL Server 2014, connection string I used is :

        Public SqlConStr As String = "Server=Server2; Database=DataFileNSteel; User Id=sa; Password=Test123#;"
    I want my whole project to switch from SQL connection string to ODBC (DSN) connection String.

    To Update record I used following Codes

            Dim SqlStr As String
            Dim cmd = New SqlCommand
           ' Update Record
            SqlStr = "Update TblTransMaster Set Dated = '" & Format(CDate(txtDate.Text), "yyyy-MM-dd") & "', VoucherNo = '" & Trim(txtVoucherNo.Text) & "', TotalAmount = " & Val(txtTotalDebitAmount.Text.Replace(",", "")) & ", UserID = " & GlbUserID & " Where Vnoc = '" & Vnoc & "' And Vnon = " & Val(txtVnon.Text)
           cmd = New SqlCommand(SqlStr, Conn)

    To save Record I used following Codes:

    SqlStr = "Insert Into TblTransMaster (Dated, VoucherNo, Vnoc, Vnon, TotalAmount, UserID, SaveDate, SaveTime, SystemName, SystemIpAddress)  Values(@Dated, @VoucherNo, @Vnoc, @Vnon, @TotalAmount, @UserID, @SaveDate, @SaveTime, @SystemName, @SystemIpAddress)"
                cmd = New SqlCommand(SqlStr, Conn)
                With cmd.Parameters
                    .AddWithValue("@Dated", Format(CDate(txtDate.Text), "yyyy-MM-dd"))
                    .AddWithValue("@VoucherNo", Trim(txtVoucherNo.Text))
                    .AddWithValue("@Vnoc", Vnoc)
                    .AddWithValue("@Vnon", Val(txtVnon.Text))
                    .AddWithValue("@TotalAmount", Val(txtTotalDebitAmount.Text.Replace(",", "")))
                    .AddWithValue("@UserID", GlbUserID)
                    .AddWithValue("@SaveDate", Format(CDate(Date.Now), "yyyy-MM-dd"))
                    .AddWithValue("@SaveTime", Now.ToShortTimeString())
                    .AddWithValue("@SystemName", My.Computer.Name)
                    .AddWithValue("@SystemIpAddress", System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList(0).ToString())
                End With

    To Fetch records I used following Codes

    Dim Qry As String = "Select * From QryTrans where Vnon = " & Val(txtVnon.Text) & " And Vnoc = '" & Vnoc & "' And Location = 'Detail'  Order by ID"
            Dim Table As New DataTable
            Dim Adapter As New SqlDataAdapter(Qry, Conn)

    Please provide me simple and quick solution to shift my whole project from SQL Connection string to ODBC (DSN) Connection string.


  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Sydney, Australia

    Re: SQL Connection string to ODBC (DSN) Connection String

    Visit www.connectionstrings.com to learn about connection strings for all sorts of data sources, including ODBC.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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