Well, I am building a small hobby program in C#, and I am trying to write information from my program to Sql
The thing is I have some varchar fields in Sql with a max length of 50
when I send information to fill those columns they will be added with extra space until reaching 50 chars
I already tried to change varchar to nvarchar just to see if it works
What I have been researching is that nchar does this kind of thing but with varchar I shouldn't have problem but I am having them..
public PersonModel CreatePerson(PersonModel model)
{
using (IDbConnection connection =
new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
{
var p = new DynamicParameters();
p.Add("@FirstName", model.FirstName);
p.Add("@LastName", model.LastName);
p.Add("@EmailAddress", model.EmailAddress);
p.Add("@CellphoneNumber", model.CellphoneNumber);
p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
connection.Execute("dbo.spPeople_Insert", p, commandType: CommandType.StoredProcedure);
model.Id = p.Get<int>("@id");
return model;
}
}
and here is how i call it
if (ValidateForm())
{
PersonModel p = new PersonModel();
p.FirstName = firstNameValue.Text;
p.LastName = lastNameValue.Text;
p.EmailAddress = emailValue.Text;
p.CellphoneNumber = cellphoneValue.Text;
those are textbox in my form btw
According to Microsoft
You need to set SET ANSI_PADDING OFF
please note that existing columns will not be be affected by changing the setting only new ones
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With