Guest User

Untitled

a guest
Oct 30th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using Microsoft.VisualBasic;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Diagnostics;
  7. using System.Data.SqlClient;
  8. static class iQuery
  9. {
  10.  
  11.     public static void Mssql_Connection(string dBase, string query)
  12.     {
  13.         SqlConnection con = new SqlConnection();
  14.         SqlCommand cmd = new SqlCommand();
  15.         int X = 0;
  16.         string User = null;
  17.         string Pass = null;
  18.         string Host = null;
  19.  
  20.         Host = iMain.TextBox1.Text;
  21.         User = iMain.TextBox2.Text;
  22.         Pass = iMain.TextBox3.Text;
  23.  
  24.         try {
  25.             con.ConnectionString = "Data Source=" + Host + ";Initial Catalog=" + dBase + ";Persist Security Info=True;User ID=" + User + ";Password=" + Pass + "";
  26.             con.Open();
  27.  
  28.             cmd = new SqlCommand(query, con);
  29.  
  30.             X = cmd.ExecuteNonQuery();
  31.             MessageBox.Show("Rows Updated: " + X);
  32.  
  33.         } catch (Exception ex) {
  34.             MessageBox.Show("Error while connecting to SQL Server." + ex.Message);
  35.         } finally {
  36.             con.Close();
  37.         }
  38.  
  39.     }
  40. }
Add Comment
Please, Sign In to add comment