Results 1 to 2 of 2

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

Hybrid View

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2010
    Posts
    323

    SQL Connection string to ODBC (DSN) Connection String

    Hi,

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

    Code:
        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

    Code:
            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)
           Cmd.ExecuteNonQuery()

    To save Record I used following Codes:

    Code:
    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
    
                cmd.ExecuteNonQuery()

    To Fetch records I used following Codes

    Code:
    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)
            Adapter.Fill(Table)

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

    Thanks
    Ladak

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    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.

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