Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
Guia_No

Guia_No

Ratings: (0)|Views: 6 |Likes:
Published by api-3711538
Anexo a la guía # 17 (código)
Anexo a la guía # 17 (código)

More info:

Published by: api-3711538 on Oct 15, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

05/09/2014

pdf

text

original

Option Explicit
Private Sub cmdAnterior_Click()

On Error Resume Next
Rx = Rx - 1
MostrarDatos
MostrarDataGrid
DataGrid1.Row = Rx

End Sub
Private Sub cmdsalvar_Click()
If ChequearDuplicado(txtid.Text) = True And

AgregarNuevo = True Then
MsgBox "Registro duplicado ", , "Error"
MostrarDatos
Set DataGrid1.DataSource = rs1
DataGrid1.Row = Rx

Else
SalvarDatos
End If
SetButton
End Sub
Private Sub cmdSqlExecutaUpdate_Click()

conn.Execute "UPDATE tblproductos SET
Nombre = '" & txtNom.Text & "' ,valor = '" &
txtprecio.Text & "' Where Id='" & txtid.Text & " '

;"

CambiarModo False, True, &HF1EEE4
MostrarDatos
Set DataGrid1.DataSource = rs1
MostrarDataGrid
DataGrid1.Row = Rx
CtrlButton True
Shape1.Visible = False
Shape3.Visible = False
cmdCancelar_Click

End Sub
Private Sub cmdUltimo_Click()

On Error Resume Next
Rx = xContador - 1
MostrarDatos
MostrarDataGrid
DataGrid1.Row = Rx

End Sub
Private Sub Form_Load()

On Error GoTo DBerror
Rx = 0
MostrarDatos
MostrarDataGrid
Exit Sub

DBerror:
CrearTabla
MostrarDatos
MostrarDataGrid

End Sub
Private Sub cmdAgregar_Click()

txtid.Text = ""
txtNom.Text = ""
txtprecio.Text = ""
AgregarNuevo = True

CambiarModo True, False, &H80000005

cmdAgregar.Enabled = False
cmdEditar.Enabled = False
cmdBorrar.Enabled = False
cmdCancelar.Enabled = True
CtrlButton False

End Sub
Private Sub cmdCancelar_Click()

CambiarModo False, True, &HF1EEE4
cmdsalvar.Enabled = False
cmdCancelar.Enabled = False
cmdEditar.Enabled = True
cmdAgregar.Enabled = True
cmdBorrar.Enabled = True
CtrlButton True
Label6.Caption = ""
Shape1.Visible = False
Shape2.Visible = False
Shape3.Visible = False
AgregarNuevo = False
MostrarDatos
Set DataGrid1.DataSource = rs1

End Sub
Private Sub cmdBorrar_Click()
BorrarDato
Rx = Rx - 1

MostrarDatos
Set DataGrid1.DataSource = rs1
MostrarDataGrid
DataGrid1.Row = Rx

End Sub
Private Sub cmdEditar_Click()
Label6.Caption = "Usted puede Modificar

datos"
CambiarModo False, False, &H80000005
cmdEditar.Enabled = False
cmdAgregar.Enabled = False
cmdBorrar.Enabled = False
cmdsalvar.Enabled = True
cmdCancelar.Enabled = True
CtrlButton False
Shape1.Visible = True
Shape3.Visible = True
AgregarNuevo = False

End Sub

Anexo guia # 17 Adodatacontrol
Preparado por Juan Carlos P\u00e9rez P.
www.esnips.com/web/desarrollo

Private Sub cmdprimero_Click()

On Error Resume Next
Rx = 0
MostrarDatos
MostrarDataGrid
DataGrid1.Row = Rx
'howImage txtid

End Sub

Private Sub cmdsiguiente_Click()
On Error Resume Next
Rx = Rx + 1
MostrarDatos
MostrarDataGrid
DataGrid1.Row = Rx

End Sub
Private Sub cmdSqlAdicionar_Click()
If ChequearDuplicado(txtid.Text) = True
ThenMsgBox "Registro Duplicado ", , "Error"
Else
conn.Execute "INSERT INTO
tblproductos(ID,Nombre,valor) values('" &

txtid & "','" & txtNom & "','" & txtprecio & "')"
End If
SetButton
cmdCancelar_Click

End Sub
Private Sub cmdNuevaTabla_Click()
CrearTabla
MostrarDataGrid
End Sub
Private Sub cmdSqlBorrar_Click()
conn.Execute "DELETE FROM

tblproductos Where Id = '" & txtid & "'"
Rx = Rx - 1
MostrarDatos
Set DataGrid1.DataSource = rs1
MostrarDataGrid
DataGrid1.Row = Rx

End Sub
Private Sub SalvarDatos()

Dim rs As ADODB.Recordset
Dim sql As String
Set rs = New ADODB.Recordset

rs.CursorLocation = adUseServer
If AgregarNuevo = True Then

rs.Open "select * from
tblproductos", conn, adOpenStatic,
adLockOptimistic, adCmdText

AgregarNuevo = False
rs.AddNew

Else
sql = "select * from tblproductos where ID = '
" & txtid.Text & " ' ;"

rs.Open sql, conn, adOpenStatic,
adLockOptimistic, adCmdText

End If
rs!ID = txtid.Text
rs!Nombre = txtNom.Text
rs!valor = txtprecio.Text
rs.Update
rs.Close
Set rs = Nothing
cmdsalvar.Enabled = False

End Sub
Private Sub cmdSqlActualizar_Click()
Dim rsTemp As ADODB.Recordset

Dim sql As String
Set rsTemp = New ADODB.Recordset
rsTemp.CursorType = adOpenDynamic
rsTemp.LockType = adLockOptimistic
rsTemp.CursorLocation = adUseServer
sql = "UPDATE tblproductos SET Nombre

= '" & txtNom.Text & "' , valor = '" &
txtprecio.Text & "' Where ID='" & txtid.Text &
"'"

rsTemp.Open sql, conn, adOpenKeyset,

adLockOptimistic
CambiarModo False, True, &HF1EEE4
MostrarDatos
Set DataGrid1.DataSource = rs1
MostrarDataGrid
DataGrid1.Row = Rx
CtrlButton True

End Sub

Anexo guia # 17 Adodatacontrol
Preparado por Juan Carlos P\u00e9rez P.
www.esnips.com/web/desarrollo

Private Sub BorrarDato()
Dim rsTemp As ADODB.Recordset

Dim sql As String
Set rsTemp = New ADODB.Recordset
rsTemp.CursorType =
adOpenDynamic
rsTemp.LockType = adLockOptimistic

rsTemp.CursorLocation = adUseServer

sql = "DELETE FROM tblproductos Where
ID='" & txtid.Text & "'"
If MsgBox("Est\u00e1 seguro que desea borrar
este registro ?", vbYesNo + vbDefaultButton2
+ vbCritical, "Confirma Borrar") = vbNo Then

Set rsTemp = Nothing
Exit Sub

End If
rsTemp.Open sql, conn, adOpenKeyset,
adLockOptimistic
Set rsTemp = Nothing

End Sub
Private Sub MostrarDatos()
Dim rs As ADODB.Recordset

Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
rs.CursorType = adOpenStatic
rs.LockType = adLockReadOnly
rs.Open "SELECT * FROM tblproductos",

conn

If rs.EOF = True Then
rs.Close
Set rs = Nothing
Exit Sub

End If
xContador = rs.RecordCount
If Rx > rs.RecordCount - 1 Then

Rx = 0
End If
If Rx < 0 Then

Rx = rs.RecordCount - 1

End If
rs.Move Rx
Set DataGrid1.DataSource = rs
txtid.Text = rs!ID
txtNom.Text = rs!Nombre
txtprecio.Text = rs!valor
'txtprecio.Text = Format(rs!ProductPrice,

"###,###,###,##0.00")
rs.Close
Set rs = Nothing

End Sub
Private Sub MostrarDataGrid()

Set rs1 = New ADODB.Recordset
rs1.CursorLocation = adUseClient
rs1.CursorType = adOpenStatic
rs1.LockType = adLockReadOnly
rs1.Open "SELECT * FROM tblproductos",

conn
Set DataGrid1.DataSource = rs1
End Sub
Private Sub CrearTabla()
On Error GoTo ServerErr
conn.Execute "DROP TABLE IF EXISTS
tblproductos"
conn.Execute "CREATE TABLE
tblproductos " _
& "(ID varchar(10) NOT NULL PRIMARY

KEY," _
& "Nombre varchar(255),valor INT," _
& "file_name VARCHAR(64) NOT NULL," _

& "file MEDIUMBLOB NOT NULL)", ,
adExecuteNoRecords
conn.Execute "INSERT INTO
tblproductos(Id,Nombre,valor)
values('A01','MB1ASUS-1',1000)", ,
adExecuteNoRecords
conn.Execute "INSERT INTO
tblproductos(Id,Nombre,valor)
values('B02','MB2GIGABYTE-2',2000)", ,
adExecuteNoRecords
conn.Execute "INSERT INTO
tblproductos(Id,Nombre,valor)
values('C03','MB3SIS-3',3000)", ,
adExecuteNoRecords
conn.Execute "INSERT INTO
tblproductos(Id,Nombre,valor)
values('D04','MB4AOPEN-4',4000)", ,
adExecuteNoRecords
conn.Execute "INSERT INTO
tblproductos(Id,Nombre,valor)
values('E05','Mainboard-5',5000)", ,
adExecuteNoRecords
Exit Sub
ServerErr:
MsgBox "No puede conectarse a MySQL
server o crear una base datos "
constr =
"Provider=MSDASQL.1;Password=;Persist
Security Info=True;User ID=;Extended
Properties=" & Chr$(34) & "DRIVER={MySQL
ODBC 3.51 Driver};DESC=;SERVER=" &
servidor_bd & ";UID=" & usuario_bd &
";PASSWORD=" & contrase\u00f1a_bd &
";PORT=" & puerto_bd &
";OPTION=16387;STMT=;" & Chr$(34)

Set conn = New ADODB.Connection
conn.Open constr
End Sub

Anexo guia # 17 Adodatacontrol
Preparado por Juan Carlos P\u00e9rez P.
www.esnips.com/web/desarrollo

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->