Ver Mensaje Individual
  #3 (permalink)  
Antiguo 06/07/2008, 17:26
Avatar de robertgustavo
robertgustavo
 
Fecha de Ingreso: marzo-2008
Ubicación: Camaná - Arequipa
Mensajes: 213
Antigüedad: 17 años
Puntos: 4
Respuesta: objetos a nivel formulario en c#

no funciona
en esta parte:

OleDbDataAdapter Da = new OleDbDataAdapter("Select * from Articulos", Cn);

Cn sale marcado dice:


Error 1 Un inicializador de campo no puede hacer referencia al campo no estático, método o propiedad 'Myprogram.FrmArticulos.Cn' C:\Documents and Settings\Roberth\Mis documentos\Visual Studio 2005\Projects\myprogram\myprogram\FrmArticulos.cs 17 79Myprogram

__________________________________________________ ______________
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.IO;

namespace MyProgram
{
public partial class FrmArticulos : Form

{
OleDbConnection Cn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|\\SismasDB.mdb");
OleDbDataAdapter Da = new OleDbDataAdapter("Select * from Articulos", Cn);
DataSet Ds = new DataSet();
DataView Dv = new DataView();
BindingSource Bs = new BindingSource();
public int Pos;
public FrmArticulos()
{
InitializeComponent();
}
private void FrmArticulos_Load(object sender, EventArgs e)
{
LlenarDatos();
FormatearGrid();
}
void LlenarDatos()
{
try
{
Da.Fill(Ds, "Articulos");
this.DgArticulos.DataSource = Ds.Tables["Articulos"];
Bs.DataSource = Ds.Tables["Articulos"];
}
catch (OleDbException ex)
{
MessageBox.Show("No se pudo conectar al origen de datos,compruebe que exista o reinstale la aplicación", "Error Inesperado", MessageBoxButtons.OK, MessageBoxIcon.Error);
Application.Exit();
}
finally
{
Ds.Clear();
Da.Fill(Ds, "Articulos");
}
}
private void FormatearGrid()
{
this.DgArticulos.Columns[0].Width = 60;
this.DgArticulos.Columns[1].Width = 120;
}
private void CerrarArticulosForm(object sender, EventArgs e)
{
this.Close();
}

private void CmdBuscarImagen_Click(object sender, EventArgs e)
{
if (OFDBuscaImagen.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
this.ImagePreview.Image = Image.FromFile(this.OFDBuscaImagen.FileName);
}
}
private void habilitarControles()
{
this.TxtCodigo.Enabled = true;
this.TxtPrecio.Enabled = true;
this.TxtPrecioCompra.Enabled = true;
this.TxtPrecioVenta.Enabled = true;
this.TxtProducto.Enabled = true;
this.TxtStock.Enabled = true;
this.TxtStockMaximo.Enabled = true;
this.TxtStockMaximo.Enabled = true;
this.CboCategoria.Enabled = true;
this.CboMarca.Enabled = true;
this.CboMedida.Enabled = true;
this.CboProveedor.Enabled = true;
this.CmdSelect1.Enabled = true;
this.CmdSelect2.Enabled = true;
this.CmdSelect3.Enabled = true;
this.CmdSelect4.Enabled = true;
this.CmdBuscarImagen.Enabled = true;
}
private void DeshabilitarControles()
{
this.TxtCodigo.Enabled = false;
this.TxtPrecio.Enabled = false;
this.TxtPrecioCompra.Enabled = false;
this.TxtPrecioVenta.Enabled = false;
this.TxtProducto.Enabled = false;
this.TxtStock.Enabled = false;
this.TxtStockMaximo.Enabled = false;
this.TxtStockMaximo.Enabled = false;
this.CboCategoria.Enabled = false;
this.CboMarca.Enabled = false;
this.CboMedida.Enabled = false;
this.CboProveedor.Enabled = false;
this.CmdSelect1.Enabled = false;
this.CmdSelect2.Enabled = false;
this.CmdSelect3.Enabled = false;
this.CmdSelect4.Enabled = false;
this.CmdBuscarImagen.Enabled = false;

}

private void CmdNuevo_Click(object sender, EventArgs e)
{
habilitarControles();
CmdGuardar.Enabled = true;
CmdNuevo.Enabled = false;
}
private void Nuevo()
{

}

private void CmdGuardar_Click(object sender, EventArgs e)
{
DeshabilitarControles();
CmdNuevo.Enabled=true;
CmdGuardar.Enabled=false;
}

}
}