Dataadapter y datagridview para c#

Solo disponible en BuenasTareas
  • Páginas : 2 (329 palabras )
  • Descarga(s) : 0
  • Publicado : 24 de febrero de 2011
Leer documento completo
Vista previa del texto
DataAdapter y DataGridView para C#

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 DataAdapter
{
public partial class Form1 : Form
{
//private DataGridView dataGridView1 = newDataGridView();
//private BindingSource bindingSource1 = new BindingSource();
//private SqlDataAdapter dataAdapter = new SqlDataAdapter();

SqlConnection cn;
DataSet ds= new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
SqlCommandBuilder cb = new SqlCommandBuilder();

public Form1()
{InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
Conexion();
dataGridView1.DataSource = bindingSource1;
}private void salvar()
{
da.Update((DataTable)bindingSource1.DataSource);
}

private void DataAdapter()
{
////Forma 1//OleDbDataAdapter da = new OleDbDataAdapter();
SqlCommand cm = new SqlCommand("select * from Tabla1", cn);
da.SelectCommand = cm;
cb = new SqlCommandBuilder(da);//Forma 2
//OleDbCommand cm = new OleDbCommand("Select * from Tabla1", cn);
//OleDbDataAdapter da = new OleDbDataAdapter(cm);
////Forma 3//SqlDataAdapter da = new SqlDataAdapter("select * from tabla1", cn);
//Llenado del DataSet
//Con este metodo no es necesario abrir y cerrar la conexion.try
{
ds.Clear();
//da.Fill(ds, "Tabla1");
//this.dataGridView1.DataSource = ds.Tables["Tabla1"];

DataTable table...
tracking img