Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
Private Sub dept_num_TextChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dept_num.TextChanged
        Dim con As SqlConnection = New SqlConnection("Data Source=S-MHAMEED\SQL2008RTWO;Initial Catalog=comp.task;User ID=...;Password=....")
        Using (con)
            Dim sqlCom As New SqlCommand()
            sqlCom.Connection = con
            sqlCom.CommandText = "Sel_dept"
            sqlCom.CommandType = CommandType.StoredProcedure
            Dim Dept_id As Boolean

            con.Open()
            Integer.TryParse(dept_num.Text, Dept_id)
            sqlCom.Parameters.AddWithValue("Dept_Id", Integer.Parse(dept_num.Text))

            'Dept_id = Convert.ToInt32(sqlCom.ExecuteScalar)
            If ("Dept_id") = False Then
                MessageBox.Show("your new record")
            End If
        End Using
    End Sub
End Class


What I have tried:

i just don't know please help
Conversion from string "Dept_id" to type 'Boolean' is not valid
Posted
Updated 11-Feb-18 0:30am
v2
Comments
Richard MacCutchan 11-Feb-18 7:22am    
You cannot compare a string of characters to a boolean value, it makes no sense. It is like saying if an apple = four o'clock.

1 solution

The comparison here
VB
If ("Dept_id") = False Then

Looks odd. You're trying to compare text with a boolean value.

Based on the commented code you're trying to find out if the execution has succeeded. Does the procedure return the new department value. If so, store it in a variable and using error handling (try...catch) ensure that the execution succeeds.

I believe that going through this tutorial might help you: Properly executing database operations[^]
 
Share this answer
 
v2
Comments
Shaddow>dark 11-Feb-18 7:09am    
TY can u replay the correct solution for this ill be thankful
Wendelius 11-Feb-18 7:23am    
What are you trying to compare in your code?
Shaddow>dark 11-Feb-18 7:39am    
???
Shaddow>dark 11-Feb-18 7:29am    
in that code i have 3 text boxes and i have button with a grid view and i activated the max number for department text box what im gonna say know that what i want i want when i insert number of the department i want it to give all details about it in the other text boxes and i want to I also want to prevent repetition in
department id ?>>>??>> that's it
Shaddow>dark 11-Feb-18 7:32am    
1 _ i wanna make it give me the details when i insert the department id give me all details in the other text boxes >>>>>>>

2 _ i wanna prevent the duplicate in department id when i insert the department id got it ???

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