hello,

I need to register a new Employee's Car ,

In my database , there are two tables ( Car_info , Emp_Info ) and I created a relation between them : (Car_info table) Column Car_no As Primary Key and (Emp_info table) Column Car_no As Foreign Key .

This is my Code :


sub Button1_Click :
Dim vCon As New SqlConnection
vCon.ConnectionString = "Data Source=....."

Dim vInsertCom As New SqlCommand

vInsertCom.Connection = vCon

vInsertCom.CommandText = "insert into Car_Info(Car_No) values(@Identity)"
vInsertCom.CommandText = "insert into Car_Info(Vehicle_Type) values(@Vehicle_Type)"
vInsertCom.CommandText = "insert into Car_Info(Car_owner) values(@Car_owner)"

vInsertCom.Parameters.Add("@Identity", SqlDbType.Int, 50).Value = TextBox1.Text
vInsertCom.Parameters.Add("@Vehicle_Type", SqlDbType.VarChar, 100).Value = TextBox3.Text
vInsertCom.Parameters.Add("@Car_owner", SqlDbType.VarChar, 100).Value = TextBox2.Text

vInsertCom.Connection.Open()

vInsertCom.ExecuteNonQuery()


End Sub

....

BUT, I have this erorr :

Cannot insert the value NULL into column 'Car_No', table 'NT.dbo.Car_info'; column does not allow nulls. INSERT fails.
The statement has been terminated.

Can someone tell me where is the problem, please?


Regards

[

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.