Akash.P Akash.P - 6 months ago 23
C# Question

Error with inserting data into the database table

When I insert data into the database table, only the first letter of the data is inserted in the columns of the database.

Here are the database tables:

enter image description here

For the employee id:102, only the first letter of the data is inserted. This is the Database Table Schema used.

I'm using C# in Visual Studio Community 2015 and SQL Server Studio Management Studio for my project.

using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TimeSheetApp
class Program
static void Main(string[] args)
string connection = ConfigurationManager.ConnectionStrings["TimeSheetAppDbConnectionString"].ToString();
var dbcontext = new TimeSheetAppDesignDataContext(connection);

int EmployeeID = 102;
string EmployeeName = "Riyas", EmployeeEmailAddress = "riyas@gmail.com", EmployeeLocation = "SriLanka";
dbcontext.insertEmployee(EmployeeID, EmployeeName, EmployeeEmailAddress, EmployeeLocation);

Console.WriteLine("Data inserted successfully");

Anyone kindly help me to resolve this error.


You're passing the data correctly, and your database structure is correct. The last clue to find the error is to check the procedure insertEmployee, the error is in the procedure and most probably in the parameters type.

Check the parameters definition for that procedure. If you're using NVARCHAR without specifying the length, then the data is being truncated to a single character because the default for NVARCHAR is NVARCHAR(1)