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