Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to pass data into a phpmyadmin database(Xampp) using a stored procedure from the database, i also intend to map my object in my code to the parameter from the stored procedure using dapper ORM. Now, when i run the code to do this, i keep getting the error above, i tried debugging i didnt see any bug in my code, i figured dapper is not passing the object from my data model into the stored procedure parameter, while debugging i was able to confirm that the object from my model was passed into the dynamic parameter object which i passed into the connection.execute command.

What I have tried:

using (IDbConnection connection = new MySqlConnector.MySqlConnection(GlobalConfig.CnnString(connectionS)))
{
foreach (OrganizationMembers model in models)
{

var p = new DynamicParameters();

string myName = "@Name";
p.Add(myName, model.Name);
p.Add("@Age", model.Age);
p.Add("@Class", model.Class);


connection.Query("organizationmembers_insert", p, commandType: CommandType.StoredProcedure);//this is where it throws an error saying the name column //cannot be null

model.Id = connection.Query<int>("dbo.SpGetId").First();

}

}// the name column in the database was indeed set as not null, but a value //was passed in the object when i ran the query
Posted
Updated 25-Sep-20 20:22pm

1 solution

The message is pretty explicit: the column "Name" cannot be a null value.
We can't see your SP, but you need to look at two things:
1) Your table definition: the "Name" column is declared as
SQL
Name NVARCHAR(...) NOT NULL
Which menas that SQL will reject any lines which do not contain actual name information.
2) Your model class, and the content of the Name property.

At a guess, model.Name is empty for some reason and that causes your INSERT to fail. But we can't look at why, because that requires you code running, the data it is processing, and your DB - and we have no access to any of them.

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. If you don't know how to use it then a quick Google for "Visual Studio 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.

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
Tobynate 28-Sep-20 19:42pm    
i have already tried debugging, and the value for the name was passed into the model,
i tried the same code and stored procedure using SQL server as my database and that works just fine, but whenever i use phpmyadmin on Xampp, i come across this problem

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