Guest User

Untitled

a guest
Oct 30th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.91 KB | None | 0 0
  1. Imports System.Data
  2. Imports System.Data.SqlClient
  3. Module iQuery
  4.  
  5.     Public Sub Mssql_Connection(dBase As String, query As String)
  6.         Dim con As New SqlConnection
  7.         Dim cmd As New SqlCommand
  8.         Dim X As Integer
  9.         Dim User, Pass, Host As String
  10.  
  11.         Host = iMain.TextBox1.Text
  12.         User = iMain.TextBox2.Text
  13.         Pass = iMain.TextBox3.Text
  14.  
  15.         Try
  16.             con.ConnectionString = "Data Source=" & Host & ";Initial Catalog=" & dBase & ";Persist Security Info=True;User ID=" & User & ";Password=" & Pass & ""
  17.             con.Open()
  18.  
  19.             cmd = New SqlCommand(query, con)
  20.  
  21.             x = cmd.ExecuteNonQuery()
  22.             MessageBox.Show("Rows Updated: " & x)
  23.  
  24.         Catch ex As Exception
  25.             MessageBox.Show("Error while connecting to SQL Server." & ex.Message)
  26.         Finally
  27.             con.Close()
  28.         End Try
  29.  
  30.     End Sub
  31. End Module
Add Comment
Please, Sign In to add comment