Files
VAR.DatabaseExplorer/VAR.DatabaseExplorer/UI/FrmDatos.cs
2018-10-24 21:28:27 +02:00

78 lines
2.1 KiB
C#

using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
namespace VAR.DatabaseExplorer.UI
{
public partial class FrmDatos : Form
{
#region Declarations
private readonly string _conexionString = string.Empty;
private readonly string _tableSchema = string.Empty;
private readonly string _tableName = string.Empty;
#endregion Declarations
#region Form life cycle
public FrmDatos(string conexionString, string tableSchema, string tableName)
{
InitializeComponent();
_conexionString = conexionString;
_tableSchema = tableSchema;
_tableName = tableName;
_conexionString = conexionString;
LoadDataFromTable();
}
private void frmDatos_Load(object sender, EventArgs e)
{
}
#endregion Form life cycle
#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 Events
#region Private methods
private void LoadDataFromTable()
{
Text = _tableSchema + @"." + _tableName;
string tableFullName = "[" + _tableSchema + "].[" + _tableName + "]";
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 Private methods
}
}