Hey
I'm trying to nsert a raw to a table that has one column marked with identity ON.
The code is like this:
string sqlString1 = "INSERT into T_Branches (BranchTypeID, BranchName) VALUES (" + _BranchType + ", '" + _BranchName + "')";
SqlConnection objConnection = new SqlConnection() ;
SqlDataAdapter objAdapater = new SqlDataAdapter( );
SqlCommand objCommand = new SqlCommand(sqlS tring1);
objConnection.C onnectionString = connectionStrin g
objConnection.O pen();
objCommand.Conn ection = objConnection;
objAdapater.Ins ertCommand = objCommand;
objAdapater.Ins ertCommand.Exec uteNonQuery();
For some reason I get the following error message:
---------------------------------------------------------------------------------------------------------
Cannot insert the value NULL into column 'BranchID', table 'CAR_RENTAL.MDF .dbo.T_Branches '; column does not allow nulls. INSERT fails.
The statement has been terminated.
--------------------------------------------------------------------------------------------------------
BranchID is the primary key and an identify column
When I try to insert values manually I succeed and the value in BranchID increments automatically
Any idea what am I doing wrong?
I'm trying to nsert a raw to a table that has one column marked with identity ON.
The code is like this:
string sqlString1 = "INSERT into T_Branches (BranchTypeID, BranchName) VALUES (" + _BranchType + ", '" + _BranchName + "')";
SqlConnection objConnection = new SqlConnection() ;
SqlDataAdapter objAdapater = new SqlDataAdapter( );
SqlCommand objCommand = new SqlCommand(sqlS tring1);
objConnection.C onnectionString = connectionStrin g
objConnection.O pen();
objCommand.Conn ection = objConnection;
objAdapater.Ins ertCommand = objCommand;
objAdapater.Ins ertCommand.Exec uteNonQuery();
For some reason I get the following error message:
---------------------------------------------------------------------------------------------------------
Cannot insert the value NULL into column 'BranchID', table 'CAR_RENTAL.MDF .dbo.T_Branches '; column does not allow nulls. INSERT fails.
The statement has been terminated.
--------------------------------------------------------------------------------------------------------
BranchID is the primary key and an identify column
When I try to insert values manually I succeed and the value in BranchID increments automatically
Any idea what am I doing wrong?
Comment