i am having web form,,in that form i am having company name in the dropdownlist,if i select the particular company name in the dropdownlist1,then the second dropdownlist will display the employee id based on the company selection,if i select the employee id,it will shows the leave balance about the particular employee,all r working fine,,
but my problem is,actually if the employee id is TCS001,i already feed the leave details to this employee,if i select the TCS001,its shows the balance cl,pl leave,and if i select the next employee Id that is TCS002,there is no leave records in the database,if there is no record means i want to show no leave records for this employee id,,but it shows an error.....
Conversion from type 'DBNull' to type 'String' is not valid.
if anything null in the database its shows an error,if i already any details in the database it will display properly..this is code
Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles drpempcode.SelectedIndexChanged
connection.ConnectionString = ("Data Source=RIFAYEE-PC;Initial Catalog=employee;Integrated Security=True")
cmd = New SqlCommand("select * from emp where empid ='" + drpempcode.Text + "' ", connection)
connection.Open()
Dim reader As SqlDataReader
reader = cmd.ExecuteReader
reader.Read()
txtempname.Text = reader(2).ToString
'TextBox13.Text = reader(33).ToString
' TextBox6.Text = reader(32).ToString
connection.Close()
cmd.Dispose()
cmd = New SqlCommand("select sum(sl) from leave where empcode like '" + drpempcode.Text + "'", connection)
connection.Open()
txttotsl.Text = cmd.ExecuteScalar
connection.Close()
cmd.Dispose()
cmd = New SqlCommand("select sum(pl) from leave where empcode like '" + drpempcode.Text + "'", connection)
connection.Open()
txttotpl.Text = cmd.ExecuteScalar
connection.Close()
cmd.Dispose()
connection.Close()