Ver Mensaje Individual
  #5 (permalink)  
Antiguo 09/11/2008, 17:43
Mayanezv
 
Fecha de Ingreso: noviembre-2008
Mensajes: 5
Antigüedad: 15 años, 6 meses
Puntos: 0
Respuesta: Eliminar fila en Datagrid

HOLA, DISULPEN PERO SOY NUEVO EN ESTO, SOY UN ESTUDIANTE DE PROGRAMACION Y ESTOY HACIENDO UNA AGENDA..... UNA DE LAS DUDAS QUE TENGO QUE COMO PODER ELIMINAR UNA FILA DIRECTAMENTE DEL DATAGRIDVIEW, YA QUE ESTOY BORRANDO POR FECHA Y NO ME GUSTA COMO QUEDA, YA QUE COMO ES UNA AGENDA SE PUEDE INGRESAR VARIOS EVENBTOS PA UNA MISMA FECHA, ENTONCES SE ME OCURRIO SI SE PUEDE BORRAR LA FILA QUE EL USUARIO QUIERA DIRECTAMENTE DEL DATADRID...... COMO NO SE MUCHO DE ESTO NO ENTIENDO LAS RESPUESTA A LOS OTROS MENSAJE POR ESO ENVIARE EL CODIGO DEL FORMULARIO BORRAR QUE HICE....POR FAVOR SI ME PUEDEN EXPLICAR CON MMANZANAS ...JAJAJ GRACIAS
RL PRIMERO ES EL BOTON BORRAR.. QUE ESTA DIRIGIDO A LA FECHA INGRESADA PREVIAMENTE....
EL SEGUNDO ESTOY CARGANDO LOS DATOS EN EL DATAGRIVIEW EN EL FORMULARIO

Imports System.Data
Imports System.Data.SqlClient
Public Class FormBorrar


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


'la conexion a la BD
Dim miCon As New SqlConnection
miCon.ConnectionString = _
"Data Source=(local)\SQLEXPRESS;" & _
"Initial Catalog=AgendaMarco;" & _
"Integrated security=true"

'Probamos la conexion
miCon.Open()

'creamos un comando
Dim micomando As New SqlCommand

'le indicamos la conexion a utilizar
micomando.Connection = miCon

'ahora la sentencia sql para borrar
micomando.CommandText = _
"DELETE FROM AgendaMarco WHERE " & _
" Fecha='" & DateTimePicker1.Text & "'"



Dim mensaje As String
mensaje = MsgBox("Seguro que desea borrar", vbYesNo + vbQuestion, "Borrar")
If mensaje = vbYes Then
micomando.ExecuteNonQuery()
Else
MsgBox("No se ha borrado", MsgBoxStyle.Information, "Aviso")



End If

End Sub


Private Sub FormBorrar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'creamos un objeto connection
Dim miConn As New SqlConnection
miConn.ConnectionString = _
"Data source=(local)\SQLEXPRESS;" & _
"initial catalog=AgendaMarco;" & _
"integrated security=true"
'ABRIMOS LA CONECCION
miConn.Open()


'creamos un comando
Dim micomando As New SqlCommand

'le indiacmos cual es la conexion a utilizar
micomando.Connection = miConn

'le entregamos un comando sql
micomando.CommandText = _
"select * from AgendaMarco"

'creamos un dataadapter
Dim mida As New SqlDataAdapter

'ejecuta el comando
mida.SelectCommand = micomando

'creemos u ndata set
Dim mids As New DataSet

'llamemos al dataset por medio del dataadapter
mida.Fill(mids)

'mostramos los resultados de la consulta
DataGridView1.DataSource = mids
DataGridView1.DataMember = mids.Tables(0).ToString
End Sub

End Class