this is the "public void RegistreerNieuweUser" where you asked for with his exception:
public void RegistreerNieuweUser(AccountGegevens account, int dropdownlijstSelectie)
{
SqlConnection con = new SqlConnection(this.connectionstring);
string strProduct;
SqlCommand cmd;
try
{
strProduct =
"insert into contactGegevens (voorNaam, achterNaam, straat, nr, postcodeID, email, gsm, telefoon, klantID) values (@voorNaam, @achterNaam, @straat, @nr, @postcodeID, @email, @gsm, @telefoon, @klantID);";
cmd = new SqlCommand(strProduct, con);
cmd.Parameters.AddWithValue("@klantID", this.VulKlantTabel(account));
cmd.Parameters.AddWithValue("@voorNaam", account.VoorNaam);
cmd.Parameters.AddWithValue("@achterNaam", account.AchterNaam);
cmd.Parameters.AddWithValue("@straat", account.Straat);
cmd.Parameters.AddWithValue("@nr", account.Nr);
cmd.Parameters.AddWithValue("@postcodeID", account.PostcodeId);
cmd.Parameters.AddWithValue("@email", account.Email);
cmd.Parameters.AddWithValue("@gsm", account.Gsm);
cmd.Parameters.AddWithValue("@telefoon", account.Telefoon);
con.Open();
cmd.ExecuteNonQuery();
}
catch (Exception)
{
;
}
finally
{
con.Close();
}
}
And I get this exception:
System.Data.SqlClient.SqlException was caught
Message=Cannot insert the value NULL into column 'contactGegevensID', table 'urlcv.dbo.contactGegevens'; column does not allow nulls. INSERT fails.
The statement has been terminated.
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=16
LineNumber=1
Number=515
Procedure=""
Server=mssql.urlcv.com
State=2
StackTrace:
bij System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
bij System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
bij System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
bij System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
bij System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
bij System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
bij System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
bij System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
bij System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
bij CurtsJam.Daos.RegistreerNieuweUser(AccountGegevens account, Int32 dropdownlijstSelectie) in C:\Users\gebruiker\Desktop\Bureaublad .NET\backups ecommerce 3\CurtsJam Online - kopieReserve\CurtsJam - E-commerce deel3 implementatie\CurtsJam\daos\Daos.cs:regel 355
InnerException:
This is the function that generate the cliend ID:
public int VulKlantTabel(AccountGegevens account)
{
int werknemerID = 0;
SqlConnection con = new SqlConnection(this.connectionstring);
string strProduct;
SqlCommand cmd;
try
{
strProduct =
"insert into klant (klantLogin, gebruikersNaam, geheimeVraag) values (@klantLogin, @gebruikersNaam, 'mars') " + "SELECT SCOPE_IDENTITY();";
cmd = new SqlCommand(strProduct, con);
cmd.Parameters.AddWithValue("@klantLogin", account.Paswoord);
cmd.Parameters.AddWithValue("@gebruikersNaam", account.GebruikersNaam);
cmd.Parameters.AddWithValue("@geheimeVraag", account.GeheimeVraag);
con.Open();
werknemerID = Convert.ToInt32(cmd.ExecuteScalar().ToString());
}
catch (Exception)
{
;
}
finally
{
con.Close();
}
return werknemerID;
}
And this is the exception I get in "Public int vulKlantTabel" function:
System.Data.SqlClient.SqlException was caught
Message=Cannot insert the value NULL into column 'klantID', table 'urlcv.dbo.klant'; column does not allow nulls. INSERT fails.
The statement has been terminated.
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=16
LineNumber=1
Number=515
Procedure=""
Server=mssql.urlcv.com
State=2
StackTrace:
bij System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
bij System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
bij System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
bij System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
bij System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
bij System.Data.SqlClient.SqlDataReader.get_MetaData()
bij System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
bij System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
bij System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
bij System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
bij System.Data.SqlClient.SqlCommand.ExecuteScalar()
bij CurtsJam.Daos.VulKlantTabel(AccountGegevens account) in C:\Users\gebruiker\Desktop\Bureaublad .NET\backups ecommerce 3\CurtsJam Online - kopieReserve\CurtsJam - E-commerce deel3 implementatie\CurtsJam\daos\Daos.cs:regel 474
InnerException:
Thanks for the fast reply!
Kurt