Solved

Error when saving to sql table a '/'

Posted on 2016-11-07
5
17 Views
Last Modified: 2016-11-07
We have problem with a specific row when saved and even noticed this type of error

Msg 213, Level 16, State 1, Line 29
Column name or number of supplied values does not match table definition.

Open in new window

After checking what was happening we noticed a user decided to use  "/" and iserted ion the transaction code.  So when the transacion is saved via the apps, we get the error above:

The error occur when:

INSERT INTO tablename VALUES ('TRAN/1002',0,0,0)

Open in new window


How can we save to our ms sql tables even though a user decided to use "/"?
0
Comment
Question by:rayluvs
  • 3
  • 2
5 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 41877901
Supply the column names in your INSERT clause.

INSERT INTO tablename (ColumnA, ColumnB, ColumnC, ColumnD)
VALUES ('TRAN/1002',0,0,0)

Open in new window


>we noticed a user decided to use  "/" and iserted ion the transaction code.
Assuming TransactionCode is where ColumnA is in the above example, guessing it is a numeric data type and the slash makes it a string, so you'll have to have some kinda of data validation step to prevent an attempted insert of a string into a numeric column.
0
 

Author Comment

by:rayluvs
ID: 41877905
Yes thanx!
0
 

Author Comment

by:rayluvs
ID: 41877909
FYI:
The format of each columns is
ColumnA = nvarchar(255)
ColumnB = float
ColumnC = float
ColumnD = float

If columnA is already non-numeric, why the error?
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 41877912
How many columns are in this table?  If there's more than four, and the INSERT statement does not explicitly define the column order, then the INSERT will happen in the order the columns exist, which means if an id or other numeric column is the first one in the table then that's where the 'TRAN/1002' will be inserted.

Another possibility is that there is a column not referenced in the INSERT statement that is defined as NOT NULL.
0
 

Author Comment

by:rayluvs
ID: 41877949
Yes, it has 6 columns.

Ok, understood, thanx!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now