sql server - Column name or number of supplied values does not match table definition - Unable to identify the root cause -


getting error on

cmd.executenonquery()

my current code

using con new sqlconnection(sconstring)     using cmd new sqlcommand(         "insert mc_entry values(" &         "@0,@1, @2, @3, @4, @5,@6,@7,@8,@9,@10,@11,@12,@13,@14,@15,@16,@17," &         "@18, @19, @20, @21, @22,@23,@24,@25,@26,@27,@28,@29,@30,@31,@32,@33,@34," &         "@35, @36, @37, @38, @39,@40,@50,@51,@52,@53,@54)", con)          myincremental = 0 54             cmd.parameters.addwithvalue("@" & myincremental, vvalues(myincremental))         next myincremental          'debug.print(ubound(vvalues))         'debug.print(lbound(vvalues))         'debug.print(join(vvalues, vbtab))           con.open()         cmd.executenonquery()         con.close()     end using end using 

lowerbound value of vvalues = 0
and
upperbound value of vvalues = 54

i having 55 columns in sql server table no incremental field , every field can accept null value.

not sure why getting error since seems okay...

column name or number of supplied values not match table definition.

any suggestions?

based on answer post, made in loop not miss necessary strings in future.

for = 0 54     redim preserve sfields(0 i)     sfields(i) = "@" & next  sconcat = join(sfields, ",")  using con new sqlconnection(sconstring)     using cmd new sqlcommand("insert mc_entry values(" & sconcat & ")", con)          = 0 54             cmd.parameters.addwithvalue("@" & i, vvalues(i))         next          con.open()         cmd.executenonquery()         con.close()     end using end using 

totally have 55 columns in table , missing parameters @41 @49, causing error.

include below solve problem

"insert mc_entry values(" & "@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17," & "@18, @19, @20, @21, @22, @23, @24, @25, @26, @27, @28, @29, @30, @31, @32, @33," & "@34, @35, @36, @37, @38, @39, @40, @41, @42, @43, @44, @45, @46, @47, @48, @49," & "@50, @51, @52, @53, @54)", con) 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -