
28/02/2008, 20:00
|
 | Colaborador | | Fecha de Ingreso: septiembre-2007 Ubicación: San Francisco, United States
Mensajes: 3.858
Antigüedad: 17 años, 5 meses Puntos: 87 | |
Re: Llenar un ComboBox en Windows forms Con un DataTable
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection("data source=.;initial catalog=deepra;uid=sa;pwd=;");
SqlDataAdapter ad;
SqlCommandBuilder cbuilder;
DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
}
private void BtnLoad_Click(object sender, EventArgs e)
{
ad = new SqlDataAdapter("select * from student", con);
cbuilder = new SqlCommandBuilder(ad);
ad.InsertCommand = cbuilder.GetInsertCommand();
ad.UpdateCommand = cbuilder.GetUpdateCommand();
ad.DeleteCommand = cbuilder.GetDeleteCommand();
dt.Clear();
ad.Fill(dt);
dataGridView1.DataSource = dt;
}
private void BtnUpdate_Click(object sender, EventArgs e)
{
DataTable changetData= dt.GetChanges();
if(changetData!=null)
{
ad.Update(dt);
MessageBox.Show("Updated");
}
}
private void BtnCancel_Click(object sender, EventArgs e)
{
DataTable changetData = dt.GetChanges();
if (changetData != null)
{
dt.RejectChanges();
MessageBox.Show("RollBacked");
}
}
}
Saludos
peter |