Hi guys, how are you doing?
Im having a vb.net exam next monday and im in serious need of your knowledge here cause our teacher ... just told us to "memorize" the code since he didnt had time to explain it, and, at least i, cant work that way.
so, basically here's the PDF he gave us with the assignment we need to memorize, more precisely the "producto" class:
http://www.filedropper.com/comohacerunabmen1capaconvisualbasicdotnet
I know its in spanish but you guys will understand what the code is doing, but ill give you guys a quick rundown:
basically i need to insert and search data into an Access DB from a windows form.
I dont know why we need to do in the middle a class that contains a few methods, among them the insert, update, erase, obtain type for a combofix and search)
Thing is, even tho it has a few comments in the first method, it doesnt describe much about whats the heck we're doing or how this works exactly.
My doubt begins in the insert method (bottom of page 13, where it reads 6.2.2.2)
For example, when it does:
12. Dim cmd_insertar = "INSERT INTO Productos (nombre, rubro_id, precio, stock, fechaInicioComercial) " & " VALUES (@nombre, @rubro_id, @precio, @stock, @fechaInicioComercial)"
I dont know what values im refering to for the INSERT INTO ( X , X, X ,X)
Are those the access registers? Same with the VALUES part
What am i referencing to with those values that begin with @, to the form, class, access?
Moving to:
29. comando.Parameters.Add(New OleDbParameter("@nombre", Me.Nombre))
30. comando.Parameters.Add(New OleDbParameter("@rubro_id", Me.Rubro))
31. comando.Parameters.Add(New OleDbParameter("@precio", Me.Precio))
32. comando.Parameters.Add(New OleDbParameter("@stock", Me.Stock))
33. comando.Parameters.Add(New OleDbParameter("@fechaInicioComercial", Me.FechaInicio))
I would like to know exactly what this line is for ("parameters.add(new oledbparameter..."), and talking about the values, the first one, same, what do the values that beging @ are referencing to? (form, class, access db).
The second one, that begins with me.X is making reference to the properties of the class, right?
And what does this one do exactly? sends the values?
38. comando.ExecuteNonQuery()
And from this ones i just dont understand anything at all:
42. Dim cmd_select = "select @@identity"
43. comando = New OleDbCommand(cmd_select, conexion)
44. Dim dt = New DataTable()
45. Dim da = New OleDbDataAdapter(comando)
46. da.Fill(dt)
47. Me.Codigo = Convert.ToInt32(dt.Rows(0)(0)) 'Obtengo el valor y se lo asigno al atributo Codigo.
51. conexion.Close()
54. Return Me.Codigo
What the heck is @@identity? what is a datatable? why am i using one for? what is that oledbdataadapter? how about da.fill and "convert.toint32(dt.rows...", what is going on?
And the same with the other methods cause they are not even commented.
Please lend me a hand, guys, im desperate.
Thanks a lot for reading and your help beforehand.
Big Hug.
Im having a vb.net exam next monday and im in serious need of your knowledge here cause our teacher ... just told us to "memorize" the code since he didnt had time to explain it, and, at least i, cant work that way.
so, basically here's the PDF he gave us with the assignment we need to memorize, more precisely the "producto" class:
http://www.filedropper.com/comohacerunabmen1capaconvisualbasicdotnet
I know its in spanish but you guys will understand what the code is doing, but ill give you guys a quick rundown:
basically i need to insert and search data into an Access DB from a windows form.
I dont know why we need to do in the middle a class that contains a few methods, among them the insert, update, erase, obtain type for a combofix and search)
Thing is, even tho it has a few comments in the first method, it doesnt describe much about whats the heck we're doing or how this works exactly.
My doubt begins in the insert method (bottom of page 13, where it reads 6.2.2.2)
For example, when it does:
12. Dim cmd_insertar = "INSERT INTO Productos (nombre, rubro_id, precio, stock, fechaInicioComercial) " & " VALUES (@nombre, @rubro_id, @precio, @stock, @fechaInicioComercial)"
I dont know what values im refering to for the INSERT INTO ( X , X, X ,X)
Are those the access registers? Same with the VALUES part
What am i referencing to with those values that begin with @, to the form, class, access?
Moving to:
29. comando.Parameters.Add(New OleDbParameter("@nombre", Me.Nombre))
30. comando.Parameters.Add(New OleDbParameter("@rubro_id", Me.Rubro))
31. comando.Parameters.Add(New OleDbParameter("@precio", Me.Precio))
32. comando.Parameters.Add(New OleDbParameter("@stock", Me.Stock))
33. comando.Parameters.Add(New OleDbParameter("@fechaInicioComercial", Me.FechaInicio))
I would like to know exactly what this line is for ("parameters.add(new oledbparameter..."), and talking about the values, the first one, same, what do the values that beging @ are referencing to? (form, class, access db).
The second one, that begins with me.X is making reference to the properties of the class, right?
And what does this one do exactly? sends the values?
38. comando.ExecuteNonQuery()
And from this ones i just dont understand anything at all:
42. Dim cmd_select = "select @@identity"
43. comando = New OleDbCommand(cmd_select, conexion)
44. Dim dt = New DataTable()
45. Dim da = New OleDbDataAdapter(comando)
46. da.Fill(dt)
47. Me.Codigo = Convert.ToInt32(dt.Rows(0)(0)) 'Obtengo el valor y se lo asigno al atributo Codigo.
51. conexion.Close()
54. Return Me.Codigo
What the heck is @@identity? what is a datatable? why am i using one for? what is that oledbdataadapter? how about da.fill and "convert.toint32(dt.rows...", what is going on?
And the same with the other methods cause they are not even commented.
Please lend me a hand, guys, im desperate.
Thanks a lot for reading and your help beforehand.
Big Hug.
Last edited by a moderator: