Solved

SQL DATA BASE COLUMNS

Posted on 2012-12-24
10
533 Views
Last Modified: 2012-12-25
I ahve an SQL data base with 15 columns.   The data base is updated by two different forms with different infomation; however, information that is needed to be drawn into a gridview.

My issue is the forms do not insert data into the columns utilized by the other form which is throwing the following error:

Column name or number of supplied values does not match table definition.

Is there a work around for this?
0
Comment
Question by:BOEING39
  • 4
  • 3
  • 3
10 Comments
 
LVL 22

Expert Comment

by:Steve Wales
Comment Utility
You'll need to modify the forms / programs - whatever the code is that updates the table.

Make sure that the code for the inserts is inserting the correct number of columns, with the correct data types.

If you want to be sure, you can specify the column names in the insert statement:

insert into mytable(col1, col2, col3)
values (data_for_col1, data_for_col1, data_for_col3);
0
 

Author Comment

by:BOEING39
Comment Utility
The columns are correct that are being inserted.   I am new to SQL; however, I guess my question here is does the number of table categories or columns have to match the form?   The table contains 15 columns.  

Form 1 uses 10 of those and Form 2 uses the other 5.    When I delete the 5 columns used on the 2nd form from SQL Server , Form 1 work just fine.

In MS Access this made no difference.  I could have as many columns in the table as I needed which were not all used with each individual form.
0
 
LVL 22

Expert Comment

by:Steve Wales
Comment Utility
Well, depends how your columns are defined.

If you have the 5 that aren't used defined to allow nulls, you could just insert the 10 that form 1 uses, and have the others as nulls.

Alternatively, if the table is defined so that everything is not null, then you will need to provide a value even if it's just a space or a zero.

Let's say I have a table that looks like this:

create table tab1 (keycol int, col1 char(10), col2 char(10))

If form 1 uses the key column and col1 and form 2 uses the key column and col2, I could do this:

Form 1:
insert into tab1 (keycol, col1) values (@variable1, @variable2)

Then on Form 2:
insert into tab1 (keycol, col2) values (@variable1, @variable2)

Since the columns aren't defined as not null, the 2 values for each insert are inserted as stated, the unspecified column is null.

However, since you're getting a column error, I'm guess that's not the issue.  The columns are probably defined as not null.

Can you provide the table definition and the insert code from the 2 forms ?  (mask table and column names with generic tab1, col1 type syntax if you prefer.
0
 
LVL 2

Expert Comment

by:corvetteguru
Comment Utility
Are you using stored procedures or scripted SQL?

This error means, simply put, the number of items you are updating does not match the number that need to be updated.

There are two causes, the above mentioned no nulls field or the proc is wrong.

I tend to agree that the null fields is the problem.
0
 

Author Comment

by:BOEING39
Comment Utility
When asking original question I explain the defaultMCO below shares the same columns in some cases.   I have attached the code behind for both forms as well as the server setup.
Key.doc
default.aspx.cs
defaultMCO.aspx.cs
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:BOEING39
Comment Utility
The only no null field is ID.....
0
 
LVL 22

Expert Comment

by:Steve Wales
Comment Utility
Problem is in defaultMCO.aspx.cs

There are 15 columns in the table.  You're inserting 12 values:

        cmd.CommandText = ("INSERT into AOS VALUES (@AOSdate,@Sta,@Ship,@ATA,@InFLt,@ArrTime,@Status,@MCOissuedBy,@History,@ETR,@Reason1,@MCOInst)");

        cmd.Parameters.AddWithValue("@AOSdate", AOSdate.Text);
        cmd.Parameters.AddWithValue("@Sta", Sta.SelectedValue);
        cmd.Parameters.AddWithValue("@Ship", Ship.SelectedValue);
        cmd.Parameters.AddWithValue("@ATA", ATA.SelectedValue);
        cmd.Parameters.AddWithValue("@InFlt", InFlt.Text);
        cmd.Parameters.AddWithValue("@ArrTime", ArrTime.Text);
        cmd.Parameters.AddWithValue("@Status", Status.SelectedValue);
        cmd.Parameters.AddWithValue("@MCOissuedBy", MCOissuedBy.SelectedValue);
        cmd.Parameters.AddWithValue("@History", History.SelectedValue);
        cmd.Parameters.AddWithValue("@ETR", ETR.SelectedValue);
        cmd.Parameters.AddWithValue("@Reason1", Reason1.Text);
        cmd.Parameters.AddWithValue("@MCOInst", MCOInst.Text);


Since the table is not allowing nulls, you are required to specify all 15 values.

Also since you're not specifying any column names, you need to have the 15 columns in the same order in the insert statement as they appear in the table.  These 12 values are all jumbled up.

You can change up the order if you specify the columns names (like I mentioned in one of my earlier replies).

Make the insert look like the one in the other form (Correct order, specifying all values) and your problem should go away.
0
 
LVL 2

Accepted Solution

by:
corvetteguru earned 500 total points
Comment Utility
I see the problem...

You have this insert statement:

INSERT into AOS VALUES (@AOSdate,@Sta,@Ship,@ATA,@InFLt,@ArrTime,@Status,@MCOissuedBy,@History,@ETR,@Reason1,@MCOInst)

Do this:

INSERT into AOS
(AOSdate,Sta,Ship,ATA,InFLt,ArrTime,Status,MCOissuedBy,History,ETR,Reason1,MCOInst)
VALUES (@AOSdate,@Sta,@Ship,@ATA,@InFLt,@ArrTime,@Status,@MCOissuedBy,@History,@ETR,@Reason1,@MCOInst)

Using the field list will stop errors like your's...
0
 

Author Closing Comment

by:BOEING39
Comment Utility
Corvetteguru:


Right on the mark.    Thank you.

cmd.CommandText = ("INSERT into AOS (AOSdate,Ship,ArrTime,InFLt,History,ETRDate,ETRTime,Sta,Reason1,Reason2,Parts,Updated,ATA,Status,ETR) VALUES (@AOSdate,@Ship,@ArrTime,@InFlt,@History,@ETRDate,@EtrTime,@Sta,@Reason1,@Reason2,@Parts,@Updated,@ATA,@Status,@ETR)");
0
 
LVL 2

Expert Comment

by:corvetteguru
Comment Utility
You are most welcome! Now... enjoy your Holiday! :)
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

744 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

15 Experts available now in Live!

Get 1:1 Help Now