Click here to Skip to main content
16,012,352 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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=sa;Password=likebefore")
        Using (con)

            Dim dt As New DataTable
            Dim sqlCom As New SqlCommand()
            Dim sqlDA As New SqlDataAdapter()

            sqlCom.Connection = con
            sqlCom.CommandText = "insert_dept"
            sqlCom.CommandType = CommandType.StoredProcedure
            sqlCom.Parameters.AddWithValue("dept_id", Val(dept_num.Text))
            sqlDA = New SqlDataAdapter(sqlCom)
            sqlDA.Fill(dt)

            If dt.Rows.Count Then
                dept_name.Text = dt.Rows(0).Item("debt_name")
                emp_num.Text = dt.Rows(0).Item("debt_emp")
            End If

        End Using


What I have tried:

i want to fill data when i insert the id in id text box Here is my code but when i insert id dept nothing shows ??? 
Posted
Updated 12-Feb-18 20:31pm
Comments
Animesh Datta 13-Feb-18 2:34am    
put your store procedure in the question.
Shaddow>dark 13-Feb-18 3:26am    
ALTER PROCEDURE [dbo].[insert_dept]

@dept_id INT = NULL,
@debt_name NVARCHAR(50) = NULL,
@debt_emp NUMERIC(18) = NULL

AS
BEGIN

IF NOT EXISTS(SELECT 1 FROM Department WHERE dept_id = @dept_id)
BEGIN
INSERT INTO dbo.Department (dept_id ,debt_name ,debt_emp )
VALUES (@dept_id ,@debt_name ,@debt_emp )
END
ELSE
BEGIN

UPDATE dbo.Department
SET debt_name=@debt_name ,debt_emp=@debt_emp
WHERE dept_id=@dept_id

END

END

1 solution

Just as with your last question, we still can't read your SP, we can't tell what your tables look line, we can't access your data, we can;t tell what you are passing.

All all of that is essential to solve this problem.
So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. How you use it depends on your compiler system, but a quick Google for the name of your IDE and "debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.
Look at exactly what is in dept_num.Text, use SSMS to SELECT all matchign rows (after you look at the SP to find out exactly what it does) and see what is going to be returned. Then follow your code through as see what is returned.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
Comments
Shaddow>dark 13-Feb-18 3:22am    
Thank You Very Much For Your Answer it's Very useful and your Good Dude i like it all of it Btw i can debugging but my problem is how to find the Error and the problem i'm just new in the company and its the first time i work my study was very different from the work i'm trying the best to know how to code in my company no one helps me i'm on my self it's hard to do such a thing without somebody help u and update you and learn you how to work in every code solve another problem shows up and that's blowing up my mind what should i do ?????
your professional and i'm just like your student
OriginalGriff 13-Feb-18 3:32am    
If you can debug, then you know that the most important thing is gathering information, and look to see what - exactly - happens to it.
"Finding the error" is all about working out what is going on - and without access to your code and data while it is running you just can't do that.
So stop panicking, set a breakpoint and start looking! We really can't do that for you! :laugh:

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