D
Dhananjay
Hi all,
I have problem with delete functionality in a web page.First i am
populating data in Dropdownlist, and on the same page i want to remove
the data from same Dropdownlist with buttonDelete_Click event.
First what i wanted to populate data in Dropdownlist ---> it's
working fine.
next, based on the selected item from Dropdown list i wanted to remove
the data from Dropdownlist based on the button click event --- not
working .
Can any please help me to solve this issue. I am providing code also
so that you can easily troubleshoot the problem.
my code --->
Public Sub page_Load(ByVal sender As Object, ByVal e As EventArgs)
Handles Me.Load
PanelForEdit.Visible = False
If Not Page.IsPostBack = True Then
Dim dbcon As SqlConnection
dbcon = New SqlConnection("Data Source=.
\SQLEXPRESS;AttachDbFilename=|DataDirectory|\HRISDB.mdf;Integrated
Security=True;User Instance=True")
Dim dbcom As New SqlCommand()
dbcom.Connection = dbcon
dbcom.CommandType = CommandType.Text
dbcom.CommandText = "Select TalentTeamID,TalentTeamName
from TalentTeam "
dbcon.Open()
Dim dr As SqlDataReader
dr = dbcom.ExecuteReader()
'While dr.Read()
ddlSelectForEdit.DataSource = dr
ddlSelectForEdit.DataBind()
'End While
dbcon.Close()
ddlSelectForEdit.SelectedIndex = 0
ddlSelectForEdit.SelectedItem.Text = "Please select name"
End If
End Sub
Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As
EventArgs) Handles btnDelete.Click
Dim TalentTeamID As Integer = ddlSelectForEdit.SelectedValue
Dim condelete As SqlConnection
condelete = New SqlConnection("Data Source=.
\SQLEXPRESS;AttachDbFilename=|DataDirectory|\HRISDB.mdf;Integrated
Security=True;User Instance=True")
Try
condelete.Open()
Dim cmddelete As New SqlCommand()
cmddelete.CommandType = CommandType.Text
cmddelete.CommandText = "Delete from TalentTeam where
TalentTeamID='" & TalentTeamID & "'"
cmddelete.ExecuteNonQuery()
Catch ex As Exception
Finally
condelete.Close()
End Try
End Sub
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As
EventArgs)
Dim TalentTeamID As Integer = ddlSelectForEdit.SelectedValue
Dim conupdate As SqlConnection
conupdate = New SqlConnection("Data Source=.
\SQLEXPRESS;AttachDbFilename=|DataDirectory|\HRISDB.mdf;Integrated
Security=True;User Instance=True")
Try
conupdate.Open()
Dim cmdupdate As New SqlCommand()
cmdupdate.Connection = conupdate
cmdupdate.CommandType = CommandType.Text
cmdupdate.CommandText = "Update TalentTeam set
TalentTeamName='" & txtForEdit.Text & "' where TalentTeamID='" &
TalentTeamID & "' "
Dim TalentTeamName As String
TalentTeamName = txtForEdit.Text.ToString()
cmdupdate.ExecuteNonQuery()
Catch ex As Exception
Finally
ddlSelectForEdit.SelectedIndex = 0
ddlSelectForEdit.SelectedItem.Text = "Please select name"
conupdate.Close()
End Try
End Sub
please provide me the solution, it's urgent.
Thanks in Advance
Dhananjay
I have problem with delete functionality in a web page.First i am
populating data in Dropdownlist, and on the same page i want to remove
the data from same Dropdownlist with buttonDelete_Click event.
First what i wanted to populate data in Dropdownlist ---> it's
working fine.
next, based on the selected item from Dropdown list i wanted to remove
the data from Dropdownlist based on the button click event --- not
working .
Can any please help me to solve this issue. I am providing code also
so that you can easily troubleshoot the problem.
my code --->
Public Sub page_Load(ByVal sender As Object, ByVal e As EventArgs)
Handles Me.Load
PanelForEdit.Visible = False
If Not Page.IsPostBack = True Then
Dim dbcon As SqlConnection
dbcon = New SqlConnection("Data Source=.
\SQLEXPRESS;AttachDbFilename=|DataDirectory|\HRISDB.mdf;Integrated
Security=True;User Instance=True")
Dim dbcom As New SqlCommand()
dbcom.Connection = dbcon
dbcom.CommandType = CommandType.Text
dbcom.CommandText = "Select TalentTeamID,TalentTeamName
from TalentTeam "
dbcon.Open()
Dim dr As SqlDataReader
dr = dbcom.ExecuteReader()
'While dr.Read()
ddlSelectForEdit.DataSource = dr
ddlSelectForEdit.DataBind()
'End While
dbcon.Close()
ddlSelectForEdit.SelectedIndex = 0
ddlSelectForEdit.SelectedItem.Text = "Please select name"
End If
End Sub
Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As
EventArgs) Handles btnDelete.Click
Dim TalentTeamID As Integer = ddlSelectForEdit.SelectedValue
Dim condelete As SqlConnection
condelete = New SqlConnection("Data Source=.
\SQLEXPRESS;AttachDbFilename=|DataDirectory|\HRISDB.mdf;Integrated
Security=True;User Instance=True")
Try
condelete.Open()
Dim cmddelete As New SqlCommand()
cmddelete.CommandType = CommandType.Text
cmddelete.CommandText = "Delete from TalentTeam where
TalentTeamID='" & TalentTeamID & "'"
cmddelete.ExecuteNonQuery()
Catch ex As Exception
Finally
condelete.Close()
End Try
End Sub
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As
EventArgs)
Dim TalentTeamID As Integer = ddlSelectForEdit.SelectedValue
Dim conupdate As SqlConnection
conupdate = New SqlConnection("Data Source=.
\SQLEXPRESS;AttachDbFilename=|DataDirectory|\HRISDB.mdf;Integrated
Security=True;User Instance=True")
Try
conupdate.Open()
Dim cmdupdate As New SqlCommand()
cmdupdate.Connection = conupdate
cmdupdate.CommandType = CommandType.Text
cmdupdate.CommandText = "Update TalentTeam set
TalentTeamName='" & txtForEdit.Text & "' where TalentTeamID='" &
TalentTeamID & "' "
Dim TalentTeamName As String
TalentTeamName = txtForEdit.Text.ToString()
cmdupdate.ExecuteNonQuery()
Catch ex As Exception
Finally
ddlSelectForEdit.SelectedIndex = 0
ddlSelectForEdit.SelectedItem.Text = "Please select name"
conupdate.Close()
End Try
End Sub
please provide me the solution, it's urgent.
Thanks in Advance
Dhananjay