Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.VisualBasic;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Data;
- using System.Diagnostics;
- using System.Data.SqlClient;
- static class iQuery
- {
- public static void Mssql_Connection(string dBase, string query)
- {
- SqlConnection con = new SqlConnection();
- SqlCommand cmd = new SqlCommand();
- int X = 0;
- string User = null;
- string Pass = null;
- string Host = null;
- Host = iMain.TextBox1.Text;
- User = iMain.TextBox2.Text;
- Pass = iMain.TextBox3.Text;
- try {
- con.ConnectionString = "Data Source=" + Host + ";Initial Catalog=" + dBase + ";Persist Security Info=True;User ID=" + User + ";Password=" + Pass + "";
- con.Open();
- cmd = new SqlCommand(query, con);
- X = cmd.ExecuteNonQuery();
- MessageBox.Show("Rows Updated: " + X);
- } catch (Exception ex) {
- MessageBox.Show("Error while connecting to SQL Server." + ex.Message);
- } finally {
- con.Close();
- }
- }
- }
Add Comment
Please, Sign In to add comment