Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim con As SqlConnection = New SqlConnection("Data Source=S-MHAMEED\SQL2008RTWO;Initial Catalog=comp.task;User ID=sa;Password=likebefore")
        Using (con)

            Dim tb As New DataTable
            Dim sqlCom As New SqlCommand()
            Dim sqqla As New SqlDataAdapter()

            sqlCom.Connection = con
            sqlCom.CommandText = "insert_emp"
            sqlCom.CommandType = CommandType.StoredProcedure
            sqlCom.Parameters.AddWithValue("Emp_num", Val(TextBox1.Text))
            sqqla = New SqlDataAdapter(sqlCom)
            sqqla.Fill(tb)

            If tb.Rows.Count Then
                ComboBox1.Text = tb.Rows(0).Item("debt_num")
                TextBox3.Text = tb.Rows(0).Item("Emp_name")
                DateTimePicker1.Text = tb.Rows(0).Item("EMP_WORK_DATE")
                TextBox5.Text = tb.Rows(0).Item("EMP_DESC")
                TextBox6.Text = tb.Rows(0).Item("DEBT_NAME")
                DateTimePicker2.Text = tb.Rows(0).Item("EMP_P_DATE")
                TextBox8.Text = tb.Rows(0).Item("EMP_SAL")

            End If

        End Using
    End Sub
End Class


What I have tried:

here's my code im looking for to figure it out but with some help here here is the error

(
Cannot insert the value NULL into column 'emp_num', table 'comp.task.dbo.Employee'; column does not allow nulls. INSERT fails. The statement has been terminated.
)
Posted
Updated 11-Feb-18 4:10am

1 solution

HERE IS MY DB SQL SP


USE [comp.task]


GO
/****** Object:  StoredProcedure [dbo].[insert_emp]    Script Date: 02/11/2018 16:22:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


ALTER  PROCEDURE [dbo].[insert_emp]
@EMP_NUM       numeric(18)   = null,
@DEBT_NUM      numeric(18)   =null,
@EMP_NAME      varchar(150)  =null,
@EMP_P_DATE    smalldatetime =null,
@EMP_WORK_DATE smalldatetime =null,
@EMP_SAL       NUMERIC(18)   =null,
@EMP_DESC      VARCHAR(250)  =null,
@DEBT_NAME     VARCHAR(150)  =null
AS
BEGIN
 IF NOT EXISTS(SELECT 1 FROM Employee  WHERE EMP_NUM  = @EMP_NUM )
	BEGIN
INSERT INTO DBO.EMPLOYEE ( DEPT_NUM ,EMP_NAME ,EMP_P_DATE ,EMP_WORK_DATE ,EMP_SAL ,EMP_DESC,DEBT_NAME )
VALUES (@DEBT_NUM,@EMP_NAME,@EMP_P_DATE,@EMP_WORK_DATE,@EMP_SAL,@EMP_DESC,@DEBT_NAME  )
END
	ELSE
	BEGIN
	UPDATE dbo.Employee 
		SET emp_num =@EMP_NUM  ,dept_num =@DEBT_NUM ,emp_name =@EMP_NAME ,emp_p_date =@EMP_P_DATE ,emp_work_date =@EMP_WORK_DATE ,emp_sal =@EMP_SAL ,emp_desc =@EMP_DESC ,debt_name =@DEBT_NAME  
		WHERE emp_num =@EMP_NUM 
		
	END
 
Share this answer
 
Comments
Maciej Los 11-Feb-18 10:10am    
This is not an naswer. PLease, delete it to avoid down-votiong. Use "Improve question" instead.
An error message is quite clear. You cannot add null into EmpId field.
Shaddow>dark 11-Feb-18 10:38am    
Are you here for help or what ???\
Maciej Los 11-Feb-18 11:12am    
If you want help, you have to respect rules of posting questions.

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