Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/03/2005, 15:42
Avatar de Sayra
Sayra
 
Fecha de Ingreso: diciembre-2004
Mensajes: 365
Antigüedad: 20 años
Puntos: 1
No funciona el delete del datagrid

chicos no me funciona le doy eliminar y no elimina
me tiene verde

aqui va mi code
<script language="VB" runat="server">

Dim MyConnection As SqlConnection
'MyConnection = New SqlConnection("SERVER=MDS01; DATABASE=be; INTEGRATED SECURITY=false;PASSWORD=sa;USER=sa")
Dim SelectCommand As String = "select * from SolicitudEmpleo"
Sub Page_Load(Sender As Object, E As EventArgs)
Dim MyConnection As SqlConnection
MyConnection = New SqlConnection("SERVER=MDS01; DATABASE=be; INTEGRATED SECURITY=false;PASSWORD=sa;USER=sa")
If Not IsPostBack

Dim ds As DataSet

Dim MyCommand As SqlDataAdapter

MyCommand = New SqlDataAdapter ("select CargoID, Nombre_Cargo from Cargo_Solicitado" , MyConnection)

ds = New DataSet ()

MyCommand.Fill(ds,"Cargo_Solicitado")

DropDownList1.DataSource = ds.Tables("Cargo_Solicitado").DefaultView
DropDownList1.DataTextField = "Nombre_Cargo"
DropDownList1.DataValueField ="CargoID"
DropDownList1.DataBind()
DropDownList1.Items.Insert(0, "Seleccione un item")
DropDownList1.SelectedIndex = 0

Dim dc As DataSet
Dim MyCommand2 As SqlDataAdapter
MyCommand2 = New SqlDataAdapter ("select ProfesionID, Nombre_Profesion from Profesion", MyConnection)
dc = New DataSet ()
MyCommand2.Fill(dc,"Profesion")

DropDownList2.DataSource = dc.Tables("Profesion").DefaultView
DropDownList2.DataTextField = "Nombre_Profesion"
DropDownList2.DataValueField = "ProfesionID"
DropDownList2.DataBind()
DropDownList2.Items.Insert(0, "Seleccione un item")
DropDownList2.SelectedIndex = 0
end if
end sub

Sub MyDataGrid_Delete(sender As Object, E As DataGridCommandEventArgs)
Dim deleteCmd As String = "DELETE FROM Authors WHERE SolicitudID = @Id;"
Dim myCommand As SqlCommand = New SqlCommand(deleteCmd, myConnection)
myCommand.Parameters.Add(New SqlParameter("@SolicitudID",SqlDbType.VarChar, 11))
' Initialize the SqlCommand "@Id" parameter to the ID of the row
' that was clicked.
myCommand.Parameters("@SolicitudID").Value = MyDataGrid.DataKeys(CInt(E.Item.ItemIndex))
' Connect to the database and delete the specified row.
myCommand.Connection.Open()
' Test whether the delete was accomplished, and display the
' appropriate message to the user.
Try
myCommand.ExecuteNonQuery()
'Message.InnerHtml = "<b>Record Deleted</b><br>"
Catch ex As SqlException
'Message.InnerHtml = "ERROR: Could not delete record"
' Message.Style("color") = "red"
End Try

' Close the connection.
myCommand.Connection.Close()
' Rebind the DataGrid to show the updated information.

bingrid (SelectCommand)
end sub

Sub Button1_click (sender As Object, e As EventArgs)

If DropDownList1.SelectedIndex then

SelectCommand += " INNER JOIN Cargo_Solicitado"
SelectCommand += " ON SolicitudEmpleo.CargoID= Cargo_Solicitado.CargoID"
SelectCommand += " WHERE SolicitudEmpleo.Cargo_Solicitado = Cargo_Solicitado.Nombre_Cargo"
SelectCommand += " AND SolicitudEmpleo.CargoID=" &DropDownList1.SelectedItem.Value
bingrid (SelectCommand)

Else if DropDownList2.SelectedIndex then

SelectCommand += " INNER JOIN Profesion"
SelectCommand += " ON SolicitudEmpleo.ProfesionID= Profesion.ProfesionID"
SelectCommand += " WHERE SolicitudEmpleo.Profesion = Profesion.Nombre_Profesion"
SelectCommand += " AND SolicitudEmpleo.ProfesionID=" &DropDownList2.SelectedItem.Value

bingrid (SelectCommand)


end if

end sub

Sub bingrid(SelectCommand as string)
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

MyConnection = New SqlConnection("SERVER=MDS01; DATABASE=be; INTEGRATED SECURITY=false;PASSWORD=sa;USER=sa")
MyCommand = New SqlDataAdapter(SelectCommand, MyConnection)

DS = new DataSet()
MyCommand.Fill(DS, "SolicitudEmpleo")

MyDataGrid.DataSource=DS.Tables("SolicitudEmpleo") .DefaultView
MyDataGrid.DataKeyField="SolicitudID"
MyDataGrid.DataBind()

end sub

</script>