You are on page 1of 3

FORMULARIO DE INICIO

using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Conexion_BD
{
public partial class frminicio : Form
{
public static string s3;
public static string db;
public frminicio()
{
InitializeComponent();
}

private void frminicio_Load(object sender, EventArgs e)


{
cmb1.SelectedIndex = 0;
}

private void btnc_Click(object sender, EventArgs e)


{
db = txtinicio.Text;
try
{
string s1 = "data source = " + txtdata.Text;
string s2 = s1 + "; initial catalog = " + txtinicio.Text;
s3 = s2 + "; integrated security = " + cmb1.Text;
SqlConnection cnn = new SqlConnection(s3);

Form1 frm = new Form1();


frm.Show();
this.Hide();

}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error al intentar abrir la
base", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void btns_Click(object sender, EventArgs e)


{
Application.Exit();
}
}
}
FORMULARIO DE LA BASE DE DATOS

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace Conexion_BD
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click_1(object sender, EventArgs e)


{
txtconsulta.ReadOnly = false;
txtconsulta.Text = "";

}
private void button2_Click(object sender, EventArgs e)
{
try
{
string sCnn;
sCnn = frminicio.s3;
SqlDataAdapter da;
DataTable dt = new DataTable();
da = new SqlDataAdapter(txtconsulta.Text, sCnn);
da.Fill(dt);
this.grid1.DataSource = dt;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,"Error al escribir la
consulta", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}

private void button3_Click(object sender, EventArgs e)


{
string aux1 = "SELECT * FROM " + cmbtablas.Text;
SqlConnection cnn = new SqlConnection(frminicio.s3);
SqlDataAdapter da = new SqlDataAdapter(aux1, cnn);
DataTable dt = new DataTable();
da.Fill(dt);
this.grid1.DataSource = dt;
}

private void Form1_Load(object sender, EventArgs e)


{

string aux2 = "select name "+"AS TABLAS"+" from sysobjects


where xtype = 'U' Order by name";
SqlConnection cnn = new SqlConnection(frminicio.s3);
SqlDataAdapter da = new SqlDataAdapter(aux2, cnn);
DataTable dt = new DataTable();
da.Fill(dt);
this.grid1.DataSource = dt;
cmbtablas.Items.Clear();
string item;

for (int i = 0; i < (grid1.Rows.Count - 1); i++)


{
item = grid1.Rows[i].Cells[0].Value.ToString();
cmbtablas.Items.Add(item);
}

cmbtablas.SelectedIndex = 0;
txtconsulta.ReadOnly = true;
this.Text= frminicio.db;

private void button1_Click(object sender, EventArgs e)


{
Application.ExitThread();
}

private void button2_Click_1(object sender, EventArgs e)


{
frminicio frm = new frminicio();
frm.Show();
this.Close();
}

You might also like