Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 18th, 2006, 10:32 AM
Authorized User
 
Join Date: Feb 2006
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to MAKO
Default Adding row to dataset in C#

Greetings everyone!

I'm having trouble with adding a new row to an existing dataset table. The row is added, but it is not displayed on the windows form when I push the button for a new registry. Please help!!! See code below:

Code:
private void tlbClientes_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
        {
            string ese = "";
            int aplicados = 0, posicion;
            string[] personales = new string[4];
            bool habil;
            DataSet miDataSet = new DataSet();
            posicion = this.BindingContext[this.dsClientes1, "Clientes"].Count-1;

            switch(tlbClientes.Buttons.IndexOf(e.Button))
            {
                case 1:
                    this.BindingContext[this.dsClientes1, "Clientes"].Position = 0;
                    break;
                case 2:
                    this.BindingContext[this.dsClientes1, "Clientes"].Position--;
                    break;
                case 3:
                    this.BindingContext[this.dsClientes1, "Clientes"].Position++;
                    break;
                case 4:
                    this.BindingContext[this.dsClientes1, "Clientes"].Position = posicion;
                    break;
                case 6:
                    DataRow r = this.dsClientes1.Tables["Clientes"].NewRow();
                    this.dsClientes1.Tables["Clientes"].Rows.Add(r);
                    this.BindingContext[this.dsClientes1, "Clientes"].Position = posicion;
                    r["IdCliente"] = idcliente;
                    /*this.txtNombre.Enabled = true;
                    this.txtDireccion.Enabled = true;
                    this.txtCedula.Enabled = true;
                    this.txtTelefono.Enabled = true;
                    this.chkStatus.Enabled = true;
                    Insertar(ref tipoaccion);
                    this.txtNombre.Focus();*/
                    //CreaIdCliente(ref idcliente);
                    break;
                case 9:
                    if(tipoaccion == 1)
                    {
                        DataRow reg = this.dsClientes1.Tables["Clientes"].NewRow();
                        this.dsClientes1.Tables["Clientes"].Rows.Add(reg);
                        miDataSet = this.dsClientes1.GetChanges(DataRowState.Added);

                        foreach(DataRow row in miDataSet.Tables["Clientes"].Rows)
                        {
                            if((row["Nombre"].ToString() != "")&&(row["Direccion"].ToString() != ""))
                            {
                                personales[0] = row["Nombre"].ToString();
                                personales[1] = row["Direccion"].ToString();
                                personales[2] = row["Cedula"].ToString();
                                personales[3] = row["Telefono"].ToString();
                                habil = this.chkStatus.Checked ? true:false;
                                mante.InsertaCliente(personales, habil);
                                aplicados++;
                            }
                        }
                        ese = aplicados > 1 ? "s":"";
                        this.stbRegistro.Text = aplicados + " " + "Registro" + ese + " aplicado" + ese;
                    }
                    else
                    {
                        miDataSet = this.dsClientes1.GetChanges(DataRowState.Modified);
                        int IdCliente;
                        foreach(DataRow row in miDataSet.Tables["Clientes"].Rows)
                        {
                            if((row["Nombre"].ToString() != "")&&(row["Direccion"].ToString() != ""))
                            {
                                IdCliente = Convert.ToInt32(row["IdCliente"]);
                                personales[0] = row["Nombre"].ToString();
                                personales[1] = row["Direccion"].ToString();
                                personales[2] = row["Cedula"].ToString();
                                personales[3] = row["Telefono"].ToString();
                                habil = this.chkStatus.Checked ? true:false;
                                //ManteMaestros.InsertaCliente(personales, habil);
                                aplicados++;
                            }
                        }
                        ese = aplicados > 1 ? "s":"";
                        this.stbRegistro.Text = aplicados + " " + "Registro" + ese + " actualizado" + ese;
                    }
                    break;

            }
MAKO - "El super simio"
__________________
MAKO - \"El super simio\"
 
Old July 21st, 2006, 09:42 AM
Authorized User
 
Join Date: Jul 2004
Posts: 69
Thanks: 0
Thanked 1 Time in 1 Post
Default

Try the SaveChanges() function of the DataSet?!? I am not 100% on this one though.

www.CoderForRent.com
Get A Computer Job!

www.ComputersComplete.com
Computer Parts & Accessories
 
Old March 11th, 2010, 08:10 AM
hu_yang
Guest
 
Posts: n/a
Default c# dataset help

yo can find a simple C# dataset tutorial from the following link:

http://csharp.net-informations.com/d...t-tutorial.htm


yang.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it possible to copy n-row to another dataset? vinod_yadav1919 BOOK: Beginning C# 2005 Databases 1 November 12th, 2008 08:53 PM
How to copy n-row to another dataset? vinod_yadav1919 C# 0 November 12th, 2008 04:48 PM
Create new row using a typed dataset humour ASP.NET 2.0 Professional 0 May 9th, 2008 09:49 PM
Adding new row ShaileshShinde Access VBA 23 July 5th, 2006 08:26 AM
adding to a dataset wilbur C# 2 April 16th, 2005 10:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.