Your SlideShare is downloading. ×
  • Like
Ejercicio sql server vs visual .net
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Ejercicio sql server vs visual .net

  • 1,057 views
Published

By Carlos Castro …

By Carlos Castro

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,057
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
104
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Public Class menuprin Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Se compara si el control esta seleccionado If RadioButton1.Checked Then registro.Show() Me.Hide() End If 'Se compara si el control esta seleccionado If RadioButton2.Checked Then modificar.Show() Me.Hide() End If 'Se compara si la propiedad del control es verdadera If RadioButton3.Checked = True Then eliminar.Show() Me.Hide() End If End Sub End Class Imports System.Data.SqlClient Public Class registro Private Sub VolverToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VolverToolStripMenuItem.Click menuprin.Show() Me.Hide() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conexion As New SqlConnection("Data Source=CASTROSQLEXPRESS;Initial Catalog=prueba;Integrated Security=True") Dim command As New SqlCommand("insertarusuario", conexion) Dim adapter As New SqlDataAdapter("mostrarusuarios", conexion) Dim datase As New DataSet command.CommandType = Data.CommandType.StoredProcedure command.Parameters.AddWithValue("@id", TextBox1.Text) command.Parameters.AddWithValue("@nom", TextBox2.Text) command.Parameters.AddWithValue("@ape", TextBox3.Text) command.Parameters.AddWithValue("@telefo", TextBox4.Text) Try conexion.Open() command.ExecuteNonQuery() Catch ex As Exception MessageBox.Show(ex.Message) Finally MsgBox("Usuario Registrado", vbInformation, "Sistema") TextBox1.Text = "" TextBox1.Enabled = "false" TextBox2.Text = "" TextBox2.Enabled = "false" TextBox3.Text = "" TextBox3.Enabled = "false" TextBox4.Text = "" TextBox4.Enabled = "false" Button1.Enabled = "false" Button2.Enabled = "true" adapter.Fill(datase)
  • 2. DataGridView1.DataSource = datase.Tables(0) conexion.Close() End Try End Sub Private Sub registro_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Button2.Enabled = "false" End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox1.Text = "" TextBox1.Enabled = "true" TextBox2.Text = "" TextBox2.Enabled = "true" TextBox3.Text = "" TextBox3.Enabled = "true" TextBox4.Text = "" TextBox4.Enabled = "true" Button1.Enabled = "true" Button2.Enabled = "false" End Sub End Class Imports System.Data.SqlClient Public Class modificar Dim Dato1, Dato2, Dato3, Dato4 As String Private Sub VolverInicioToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VolverInicioToolStripMenuItem.Click menuprin.Show() Me.Hide() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conexion As New SqlConnection("Data Source=CASTROSQLEXPRESS;Initial Catalog=prueba;Integrated Security=True") Dim command As New SqlCommand("buscausuario", conexion) Dim adapter As New SqlDataAdapter(command) Dim datase As New DataSet command.CommandType = Data.CommandType.StoredProcedure command.Parameters.AddWithValue("@id", TextBox1.Text) Try conexion.Open() command.ExecuteNonQuery() Catch ex As Exception MessageBox.Show(ex.Message) Finally TextBox1.Text = "" Button2.Enabled = "true" Button3.Enabled = "true" adapter.Fill(datase) DataGridView1.DataSource = datase.Tables(0) conexion.Close() End Try End Sub Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox5.Enabled = "false" TextBox4.Enabled = "true"
  • 3. TextBox3.Enabled = "true" TextBox2.Enabled = "true" TextBox5.Text = Dato1 TextBox2.Text = Dato2 TextBox3.Text = Dato3 TextBox4.Text = Dato4 End Sub Private Sub DataGridView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseClick Dato1 = DataGridView1.CurrentRow.Cells(0).EditedFormattedValue.ToString Dato2 = DataGridView1.CurrentRow.Cells(1).EditedFormattedValue.ToString Dato3 = DataGridView1.CurrentRow.Cells(2).EditedFormattedValue.ToString Dato4 = DataGridView1.CurrentRow.Cells(3).EditedFormattedValue.ToString End Sub Private Sub modificar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TextBox5.Enabled = "false" TextBox4.Enabled = "false" TextBox3.Enabled = "false" TextBox2.Enabled = "false" End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim conexion As New SqlConnection("Data Source=CASTROSQLEXPRESS;Initial Catalog=prueba;Integrated Security=True") Dim command As New SqlCommand("modificarusuario", conexion) Dim adapter As New SqlDataAdapter(command) Dim datase As New DataSet command.CommandType = Data.CommandType.StoredProcedure command.Parameters.AddWithValue("@id", TextBox5.Text) command.Parameters.AddWithValue("@nom", TextBox2.Text) command.Parameters.AddWithValue("@ape", TextBox3.Text) command.Parameters.AddWithValue("@telefo", TextBox4.Text) Try conexion.Open() command.ExecuteNonQuery() Catch ex As Exception MessageBox.Show(ex.Message) Finally MsgBox("Usuario Actualizado", vbInformation, "Sistema") TextBox2.Text = "" TextBox2.Enabled = "false" TextBox3.Text = "" TextBox3.Enabled = "false" TextBox4.Text = "" TextBox4.Enabled = "false" TextBox5.Text = "" TextBox5.Enabled = "false" Button3.Enabled = "false" Button2.Enabled = "false" adapter.Fill(datase) DataGridView1.Columns.Clear() conexion.Close() End Try End Sub End Class Imports System.Data.SqlClient Public Class eliminar
  • 4. Dim Dato1, Dato2, Dato3, Dato4 As String Private Sub VolverInicioToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VolverInicioToolStripMenuItem.Click menuprin.Show() Me.Hide() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conexion As New SqlConnection("Data Source=CASTROSQLEXPRESS;Initial Catalog=prueba;Integrated Security=True") Dim command As New SqlCommand("buscausuario", conexion) Dim adapter As New SqlDataAdapter(command) Dim datase As New DataSet command.CommandType = Data.CommandType.StoredProcedure command.Parameters.AddWithValue("@id", TextBox1.Text) Try conexion.Open() command.ExecuteNonQuery() Catch ex As Exception MessageBox.Show(ex.Message) Finally TextBox1.Text = "" Button2.Enabled = "true" Button3.Enabled = "true" adapter.Fill(datase) DataGridView1.DataSource = datase.Tables(0) conexion.Close() End Try End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox5.Enabled = "false" TextBox4.Enabled = "true" TextBox3.Enabled = "true" TextBox2.Enabled = "true" TextBox5.Text = Dato1 TextBox2.Text = Dato2 TextBox3.Text = Dato3 TextBox4.Text = Dato4 End Sub Private Sub DataGridView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseClick Dato1 = DataGridView1.CurrentRow.Cells(0).EditedFormattedValue.ToString Dato2 = DataGridView1.CurrentRow.Cells(1).EditedFormattedValue.ToString Dato3 = DataGridView1.CurrentRow.Cells(2).EditedFormattedValue.ToString Dato4 = DataGridView1.CurrentRow.Cells(3).EditedFormattedValue.ToString End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim conexion As New SqlConnection("Data Source=CASTROSQLEXPRESS;Initial Catalog=prueba;Integrated Security=True") Dim command As New SqlCommand("borrarusuario", conexion) Dim adapter As New SqlDataAdapter(command) Dim datase As New DataSet command.CommandType = Data.CommandType.StoredProcedure
  • 5. command.Parameters.AddWithValue("@id", TextBox5.Text) command.Parameters.AddWithValue("@nom", TextBox2.Text) command.Parameters.AddWithValue("@ape", TextBox3.Text) command.Parameters.AddWithValue("@telefo", TextBox4.Text) Try conexion.Open() command.ExecuteNonQuery() Catch ex As Exception MessageBox.Show(ex.Message) Finally MsgBox("Usuario Eliminado", vbInformation, "Sistema") TextBox2.Text = "" TextBox2.Enabled = "false" TextBox3.Text = "" TextBox3.Enabled = "false" TextBox4.Text = "" TextBox4.Enabled = "false" TextBox5.Text = "" TextBox5.Enabled = "false" Button3.Enabled = "false" Button2.Enabled = "false" adapter.Fill(datase) DataGridView1.Columns.Clear() conexion.Close() End Try End Sub End Class ALTER PROCEDURE [dbo].[borrarusuario] -- Add the parameters for the stored procedure here ( @id nvarchar(3), @nom nvarchar (50), @ape nvarchar (50), @telefo nvarchar(12) ) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here DELETE FROM usuario WHERE ide=@id and nombre=@nom and apellido=@ape and tel=@telefo END ALTER PROCEDURE [dbo].[buscausuario] ( @id nvarchar(3) ) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here SELECT * FROM usuario WHERE ide=@id ALTER PROCEDURE [dbo].[insertarusuario] ( @id nvarchar(3), @nom nvarchar(50), @ape nvarchar(70), @telefo nvarchar(15) ) AS SET NOCOUNT ON
  • 6. INSERT INTO usuario(ide, nombre, apellido, tel) VALUES (@id,@nom ,@ape,@telefo) ALTER PROCEDURE [dbo].[modificarusuario] ( @id nvarchar(3), @nom nvarchar(50), @ape nvarchar(50), @telefo nvarchar(12) ) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here UPDATE usuario SET nombre=@nom, apellido=@ape, tel=@telefo WHERE ide=@id ALTER PROCEDURE [dbo].[mostrarusuarios] AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; SELECT * FROM usuario