datasets, datatables,..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dhpacheco
    New Member
    • Feb 2008
    • 3

    datasets, datatables,..

    Hello
    I’m doing an application using VS 2005, c# for management a DB, but I new using the language, neither have experience in programming. Please could someone tell me if this is correct?
    I include a datase in my project and create variables tableadapter for each table of the dataset.
    Now I need operate the DB, using insertions is easy ‘cause the designer creates the storage procedures, but I need to get values of the BD. I thought that an option was to use Dataset variables so that alter using selects could get a copy under which to obtain datas, but don’t know how to access a method getvalue (or something like that), I need to use storage procedures that return scalar values, I’m using some but that return datasets, but have problems with variables.
    I attach the code for recomendations. Thanks for your time.

    Code:
    namespace Registro
    {
    public partial class Form1 : Form
    {
    private HojaFirmaTableAdapter HojaFirma = new HojaFirmaTableAdapter();
    private InstitucionTableAdapter Institucion = new InstitucionTableAdapter();
    private TrabajadorTableAdapter Trabajador = new TrabajadorTableAdapter();
    private SesionesTableAdapter Sesiones = new SesionesTableAdapter();
            
    private DateTime dmahmsg;
    
    public Form1()
    {
    InitializeComponent();
    }
    
    private void Form1_Load(object sender, EventArgs e)
    {
                this.hojaFirmaTableAdapter.Fill(this.registroDataSet1.HojaFirma);
                // TODO: esta línea de código carga datos en la tabla 'registroDataSet.HojaFirma' Puede moverla o quitarla según sea necesario.
    registroDataSet1.EnforceConstraints = false;
             
    dataGridView1.DataSource = HojaFirma.GetData(); // show HojaFirma table 
                                                                                   
    dataGridView2.DataSource = Institucion.GetData();//show Institucion       
                                                     // table                                                
                                                                       
    }
    
    private void button1_Click(object sender, EventArgs e)
    {
    string cbi = textBox1.Text; // Gets the code barr
    Int64 cb = Convert.ToInt64(cbi); // converts the code to put it in the 
                                       //DB 
    
    DataTable ndt = new DataTable(); // Creates a new DataTable variable 
    ndt = Trabajador.GetDataBy(cb);  // GetDataBy is a storage proc. that  
                                     //returns a DataTable with the code 
                                     // entered if it exist in the BD                                                            
    int endt = ndt.Rows.Count; // endt returns the estate of the DataTable   
                               //(empty or not)
                
    if (endt == 0)
    {
    MessageBox.Show("Worker not registered in Data Base");
    }
    else if (endt == 1)  // Worker registered
    {
    DataTable ndt1 = new DataTable(); // Creates a new DataTable variable
                    
                    
    
                                                                
                    
    // Sesion de entrada 1 
    if (dmahmsg.TimeOfDay >= new TimeSpan(8, 30, 0) && dmahmsg.TimeOfDay <= new TimeSpan(11, 30, 0))
    {
    MessageBox.Show("Sesion de entrada 1");
    }
                    
    // Sesion de entrada 2     
    else if (dmahmsg.TimeOfDay >= new TimeSpan(13, 30, 0) && dmahmsg.TimeOfDay <= new TimeSpan(17, 0, 0))
    {
    MessageBox.Show("Sesion de entrada 2");
    }
                        
    DateTime fecha = dmahmsg;
    DateTime sesionent1 = dmahmsg;
    DateTime sesionsal1 = dmahmsg;
    DateTime sesionent2 = dmahmsg;
    DateTime sesionsal2 = dmahmsg;
    DateTime sesionextent = dmahmsg;
    DateTime sesionextsal = dmahmsg;
    int cod_aus = 14;
    int h_ause = 5;
    int ext = 2;
    string obs = "denis";
    int inst = 1;
    
    HojaFirma.InsertarTrabajador(cb, fecha, sesionent1, sesionsal1,  
                                 sesionent2,sesionsal2, sesionextent, 
                                 sesionextsal,cod_aus, h_ause, ext, obs, 
                                 inst);  
    }
    dataGridView1.DataSource = HojaFirma.GetData();
    textBox1.Clear();   // Limpia el control para recibir otro codigo de
                        // barras
    }
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    You may use the update method but you still need a db connection and sql query. HTH.

    Comment

    • dhpacheco
      New Member
      • Feb 2008
      • 3

      #3
      Originally posted by kenobewan
      You may use the update method but you still need a db connection and sql query. HTH.
      hello kenobewan
      what I need to know is if there a logic methodologic in that, I mean, if it is done that way, yes I have a db connection working fine, and have some simples queries working to, but the probem is that I need to get values fromthe database, and there some ways t make storage preocedures, I'm using the ones returning datasets, that's why I create some datasets variables, but then I can't get cell values once I have the querie done. the storage preocedures that return scalar, don't work for me 'cause some problems of data types. I've found some doc talking about xmldata readers, and really I'm trying not to use those (more complex), that's why I'm need some guide about if it is the way to resolve he problem..
      thanks

      Comment

      • dhpacheco
        New Member
        • Feb 2008
        • 3

        #4
        sorry for writing again think it could be more explicative (if this word exist)

        I've not experience in languaje neither in the used of aplication using DB's. I need to know is could be a way for accesing to db, the use of dattables variables that get the result of queries (I've simples storage procedures that work fine). let's explain the problem: is a winform aplication using a datagridview, I've done the bussiness layer, and can show the datas of the DB in the datagridviwe, and used storage procedures for inserting datas in the DB and update the datagird, etc. the problem is that when I try to make and storage procedure for getting and scalar (no a dataset). that's why I would like to know how to access cells in the datatables resulting of the queries because I need to used values of the database. or a way for getting for examples int values of a db using that kind of storage procedures. more than ways of doing things I need a guide a methodology for resolving this problem, for understanding first some concepts (please don't think I asking you to give me conferencies, sorry if it could sound that way, just tell me how you could resolve this problem). the problem of getting datas, tha databse conection works ok and queries returning datatables too, the problem is how to read cell's values.

        thanks

        Comment

        • kenobewan
          Recognized Expert Specialist
          • Dec 2006
          • 4871

          #5
          Love the language - 'methodologic' & 'explicative'. This could very well end up being a 360 degree turn key solution delivered at ramp speed ;).

          Using a stored procedure is not a problem. However, execute scalar returns a single result. Execute reader should help you to fill the dataset.

          btw - simple explanations are usually good ones. If you are using a translator, try for one that doesn't complicate your message

          Comment

          Working...