0% found this document useful (0 votes)
88 views5 pages

System - Data.Sqlclient System - Data Default2 System - Web.Ui - Page Conexion Sqlconnection

This document contains code for a web form application that allows users to view, add, modify, and delete records in a database table called "Verduras" using a SqlConnection. It includes methods to load the data from the table into a GridView, insert new records, update existing records, and delete records based on user input and button clicks. The MultiView control is used to show different views for adding, modifying, and deleting records.

Uploaded by

navapdro
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views5 pages

System - Data.Sqlclient System - Data Default2 System - Web.Ui - Page Conexion Sqlconnection

This document contains code for a web form application that allows users to view, add, modify, and delete records in a database table called "Verduras" using a SqlConnection. It includes methods to load the data from the table into a GridView, insert new records, update existing records, and delete records based on user input and button clicks. The MultiView control is used to show different views for adding, modifying, and deleting records.

Uploaded by

navapdro
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

Imports System.Data.

SqlClient
Imports System.Data

Partial Class Default2

Inherits System.Web.UI.Page
Dim conexion As New SqlConnection("Data
Source=TELMEX0;Initial
Catalog=Verduras;Integrated Security=True")

Protected Sub Page_Load(ByVal sender As


Object, ByVal e As System.EventArgs) Handles
Me.Load
Call llenagrid()
End Sub
Sub limpia()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
End Sub
Sub llenagrid()
Dim datos As New DataSet
Dim adaptador As New
SqlDataAdapter("select * from Verduras",
conexion)
adaptador.Fill(datos, "verduras")
GridView1.DataSource =
datos.Tables("verduras")
GridView1.DataBind()
End Sub
Protected Sub ImageButton1_Click(ByVal sender
As Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles
ImageButton1.Click
MultiView1.ActiveViewIndex = 0
Call limpia()
End Sub

Protected Sub Button1_Click(ByVal sender As


Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim strcomando As String
strcomando = String.Format("insert into
Verduras values({0},'{1}',{2})",
CInt(TextBox1.Text), TextBox2.Text,
CDbl(TextBox3.Text))
Dim comando As New SqlCommand(strcomando,
conexion)
Try
conexion.Open()
comando.ExecuteNonQuery()
MsgBox("Registro dado de alta")
conexion.Close()
Call llenagrid()
MultiView1.ActiveViewIndex = -1
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Protected Sub Button2_Click(ByVal sender As


Object, ByVal e As System.EventArgs) Handles
Button2.Click
MultiView1.ActiveViewIndex = -1
Call limpia()
End Sub

Protected Sub Button4_Click(ByVal sender As


Object, ByVal e As System.EventArgs) Handles
Button4.Click
MultiView1.ActiveViewIndex = -1
Call limpia()
End Sub

Protected Sub Button3_Click(ByVal sender As


Object, ByVal e As System.EventArgs) Handles
Button3.Click
Dim strcomando As String
strcomando = String.Format("update
verduras set id={0}, nombre='{1}', precio={2}
where id={3}", CInt(TextBox4.Text),
TextBox5.Text, CDbl(TextBox6.Text),
CDbl(TextBox7.Text))
Dim comando As New SqlCommand(strcomando,
conexion)
Try
conexion.Open()
comando.ExecuteNonQuery()
MsgBox("Registro Modificado")
conexion.Close()
Call llenagrid()
MultiView1.ActiveViewIndex = -1
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Protected Sub ImageButton2_Click(ByVal sender


As Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles
ImageButton2.Click
MultiView1.ActiveViewIndex = 1
Call limpia()
Call modificar()
End Sub
Sub modificar()
TextBox4.Text =
GridView1.SelectedRow.Cells(1).Text
TextBox7.Text =
GridView1.SelectedRow.Cells(1).Text
TextBox5.Text =
GridView1.SelectedRow.Cells(2).Text
TextBox6.Text =
GridView1.SelectedRow.Cells(3).Text
End Sub
Sub Eliminar()
TextBox8.Text =
GridView1.SelectedRow.Cells(1).Text
TextBox9.Text =
GridView1.SelectedRow.Cells(2).Text
TextBox10.Text =
GridView1.SelectedRow.Cells(3).Text
End Sub
Protected Sub ImageButton3_Click(ByVal sender
As Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles
ImageButton3.Click
MultiView1.ActiveViewIndex = 2
Call limpia()
Call eliminar()
End Sub

Protected Sub Button6_Click(ByVal sender As


Object, ByVal e As System.EventArgs) Handles
Button6.Click
MultiView1.ActiveViewIndex = -1
Call limpia()
End Sub

Protected Sub Button5_Click(ByVal sender As


Object, ByVal e As System.EventArgs) Handles
Button5.Click
Dim strcomando As String
strcomando = String.Format("Delete from
verduras where id={0}", CInt(TextBox8.Text))
Dim comando As New SqlCommand(strcomando,
conexion)
Try
conexion.Open()
comando.ExecuteNonQuery()
MsgBox("Registro dado de baja")
conexion.Close()
Call llenagrid()
MultiView1.ActiveViewIndex = -1
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class

You might also like