Link to home
Start Free TrialLog in
Avatar of JohannSebastian
JohannSebastian

asked on

Can't enter data into SQL table

I am learning C# Express and SQL Express. I created a table following the directions in the book I am using (Head First C#, page 28). I created a table and tried to enter data into the first row. But when I finish entering the data, I get this error message:

No row was updated.
The data in row 1 was not committed.
Error Source: .Net SqlClient Data Provider.
Error Message: String or binary data would be truncated.
The statement has been terminated.
Correct the erros and retury or press ESC to cancel the change(s).

I would appreciate help with this! Here I am, anxious to learn C#, and I am stuck at this early stage! Many thanks.

Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

the problem is that your table has (at least) 1 column, for which the size is smaller than the data you want to save to.

like employee_name being varchar(20), and you try to save 'Mr Jesus Da Cruz Bernado Alberto' into that.

please cross check.
Avatar of JohannSebastian
JohannSebastian

ASKER

Dear angellll,

My table is like this:

Contact ID (key)       int                      no nulls
Name                       nvchar(50)        nulll ok
Company                 nvchar(50          null ok
Telephone               nvchar(50          null ok
Email                        nvchar(50          null ok
Client                       bit (boolean)       null ok
Last Call                 datetime               null ok

The fields I entered were:
Contact ID: (I entered nothing because it is auto generated.)
Name           Lloyd Jones
Company      Black Box Inc.
Telephone    (718)555-5638
Email             LJones@blackboxinc.com
Client            True
Last Call       5/26/07 (SQL changes this to 5/26/07 12:00:00 AM as soon as I press Return)

It seems to me I have not exceeded the length or size limit of any of these fields. (???)
please show the relevant code, or are you entering the data directly in sql server?
There is no code. I am entering the data directly (typing it in, in the fields of the first row.)

I am attaching a screen shot.


SQLerror.jpg
I erased the value in the Email field, and the row got accepted!

But I need to enter values in the email fields. Why was LJones@blackboxinc.com not accepted?
You email field could be 255 chars length... is the standard
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial