Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
C#
Private Sub btstfidcmb_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles btstfidcmb.SelectedIndexChanged
       Dim con As New SqlConnection("Data Source=ASHUTOSH-PC\SQLEXPRESS;Initial Catalog=Art Station Management System;Integrated Security=True")
       Dim com As SqlCommand
       Dim dr As SqlDataReader
       'Dim s = CInt(btstfidcmb.Text)
       Try
           con.Open()
           Dim str As String
           str = "select * from StaffRegister where stfstaffid = '" & btstfidcmb.Text & "'"
           com = New SqlCommand(str, con)
           dr = com.ExecuteReader
           While dr.Read
               stfnametxt.Text = dr.GetString(1)
               stfmnametxt.Text = dr.GetString(2)
               stflnametxt.Text = dr.GetString(3)
           End While
           con.Close()
       Catch ex As SqlException
           MessageBox.Show(ex.Message)
       End Try
   End Sub
Posted

1 solution

This is a very simple error that you could fix on your own within seconds if you know how to debug. Put a breakpoint on the line com= New SqlCommand(str, con) and I'll bet you that your variable str has "where stfstaffid = ''" or some other non-numeric value in btstfidcmb.Text.

All you have to do is fix that.
 
Share this answer
 
Comments
Ashutosh Dutondkar 27-Dec-15 4:45am    
Actually, my mistake was, I was having a numeric data type and was trying to convert to string by putting ''. But instead of '=' is I have put 'like' command for comparing the string and my error is solved now. Thanks for your Help Sir! :)
ZurdoDev 27-Dec-15 9:48am    
Glad you were able to get it worked out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900