73 lines
2.0 KiB
C#
73 lines
2.0 KiB
C#
using System;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using ServerExplorer.Code;
|
|
using System.Data.SqlClient;
|
|
|
|
namespace ServerExplorer.UI
|
|
{
|
|
public partial class FrmDatos : Form
|
|
{
|
|
#region Declarations
|
|
|
|
private readonly TablaDesc _tablaDesc;
|
|
private readonly string _conexionString = string.Empty;
|
|
|
|
#endregion
|
|
|
|
#region Form life cycle
|
|
|
|
public FrmDatos(TablaDesc tablaDesc, string conexionString)
|
|
{
|
|
InitializeComponent();
|
|
_tablaDesc = tablaDesc;
|
|
_conexionString = conexionString;
|
|
LoadDataFromTable();
|
|
}
|
|
|
|
private void frmDatos_Load(object sender, EventArgs e) { }
|
|
|
|
#endregion
|
|
|
|
#region Events
|
|
|
|
private void dgvDatos_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { }
|
|
|
|
private void dgvDatos_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
|
|
{
|
|
if (e.DesiredType == typeof(Image))
|
|
{
|
|
if (e.Value is DBNull || (e.Value is byte[] && ((byte[])e.Value).Length <= 0))
|
|
{
|
|
e.Value = new Bitmap(1, 1);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void btnRefresh_Click(object sender, EventArgs e)
|
|
{
|
|
LoadDataFromTable();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Private methods
|
|
|
|
private void LoadDataFromTable()
|
|
{
|
|
Text = _tablaDesc.Esquema + @"." + _tablaDesc.Nombre;
|
|
string tableFullName = "[" + _tablaDesc.Esquema + "].[" + _tablaDesc.Nombre + "]";
|
|
var dt= new DataTable();
|
|
var cnx = new SqlConnection(_conexionString);
|
|
var da = new SqlDataAdapter( "select * from " + tableFullName, cnx);
|
|
cnx.Open();
|
|
da.Fill(dt);
|
|
cnx.Close();
|
|
dgvDatos.DataSource = dt;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|