BOEING39
asked on
SQL DATA BASE COLUMNS
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?
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?
ASKER
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.
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.
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.
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.
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.
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.
ASKER
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
Key.doc
default.aspx.cs
defaultMCO.aspx.cs
ASKER
The only no null field is ID.....
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,@Ar rTime,@Sta tus,@MCOis suedBy,@Hi story,@ETR ,@Reason1, @MCOInst)" );
cmd.Parameters.AddWithValu e("@AOSdat e", AOSdate.Text);
cmd.Parameters.AddWithValu e("@Sta", Sta.SelectedValue);
cmd.Parameters.AddWithValu e("@Ship", Ship.SelectedValue);
cmd.Parameters.AddWithValu e("@ATA", ATA.SelectedValue);
cmd.Parameters.AddWithValu e("@InFlt" , InFlt.Text);
cmd.Parameters.AddWithValu e("@ArrTim e", ArrTime.Text);
cmd.Parameters.AddWithValu e("@Status ", Status.SelectedValue);
cmd.Parameters.AddWithValu e("@MCOiss uedBy", MCOissuedBy.SelectedValue) ;
cmd.Parameters.AddWithValu e("@Histor y", History.SelectedValue);
cmd.Parameters.AddWithValu e("@ETR", ETR.SelectedValue);
cmd.Parameters.AddWithValu e("@Reason 1", Reason1.Text);
cmd.Parameters.AddWithValu e("@MCOIns t", 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.
There are 15 columns in the table. You're inserting 12 values:
cmd.CommandText = ("INSERT into AOS VALUES (@AOSdate,@Sta,@Ship,@ATA,
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
cmd.Parameters.AddWithValu
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Corvetteguru:
Right on the mark. Thank you.
cmd.CommandText = ("INSERT into AOS (AOSdate,Ship,ArrTime,InFL t,History, ETRDate,ET RTime,Sta, Reason1,Re ason2,Part s,Updated, ATA,Status ,ETR) VALUES (@AOSdate,@Ship,@ArrTime,@ InFlt,@His tory,@ETRD ate,@EtrTi me,@Sta,@R eason1,@Re ason2,@Par ts,@Update d,@ATA,@St atus,@ETR) ");
Right on the mark. Thank you.
cmd.CommandText = ("INSERT into AOS (AOSdate,Ship,ArrTime,InFL
You are most welcome! Now... enjoy your Holiday! :)
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);