vb.net - Visual studio: ERROR: Parameter ?_1 has no default value -


i'm having problems piece of code i'm working on, i've searched around , can't seem find thing can me!


public class customercontroller

public const connection_string string = _   "provider=microsoft.ace.oledb.12.0;data source=assignment.accdb"  public sub insert(byval htdata hashtable)      dim oconnection oledbconnection = new oledbconnection(connection_string)      try         debug.print("connection string: " & oconnection.connectionstring)          oconnection.open()         dim ocommand oledbcommand = new oledbcommand         ocommand.connection = oconnection           ocommand.commandtext = _            "insert customer (title, gender, firstname, lastname, phone, address, email, dob) values (?, ?, ?, ?, ?, ?, ?, ?);"         ocommand.parameters.add("title", oledbtype.varchar, 255)         ocommand.parameters.add("gender", oledbtype.varchar, 255)         ocommand.parameters.add("firstname", oledbtype.varchar, 255)         ocommand.parameters.add("lastname", oledbtype.varchar, 255)         ocommand.parameters.add("phone", oledbtype.varchar, 255)         ocommand.parameters.add("address", oledbtype.varchar, 255)         ocommand.parameters.add("email", oledbtype.varchar, 255)         ocommand.parameters.add("dob", oledbtype.varchar, 255)            ocommand.parameters("title").value = cstr(htdata("title"))         ocommand.parameters("gender").value = cstr(htdata("gender"))         ocommand.parameters("firstname").value = cstr(htdata("firstname"))         ocommand.parameters("lastname").value = cstr(htdata("lastname"))         ocommand.parameters("phone").value = cstr(htdata("phone"))         ocommand.parameters("address").value = cstr(htdata("address"))         ocommand.parameters("email").value = cstr(htdata("email"))         ocommand.parameters("dob").value = cstr(htdata("dob"))          ocommand.prepare()          debug.print("sql: " & ocommand.commandtext)          ocommand.executenonquery()          debug.print("the record inserted.")          'if error has occurred, show error message inform user record not inserted     catch ex exception         debug.print("error: " & ex.message)         msgbox("an error occurred. record wasn't inserted.")             oconnection.close()     end try  end sub 

end class


when enter data insert database message "error: parameter ?_1 has no default value" appreciate if me!! thanks!!!

try this. if doesn't work, there might column in database requires value none supplied or may missing query. also, it's employ using blocks automatically dispose of objects such connections , commands.

public const connection_string string = "provider=microsoft.ace.oledb.12.0;data source=assignment.accdb"  public sub insert(htdata hashtable)     try         using cn = new oledbconnection(connection_string)             cn.open()             using cmd = new oledbcommand("insert customer (title, gender, firstname, lastname, phone, address, email, dob) values (?,?,?,?,?,?,?,?)", cn)                 cmd.parameters                     .addwithvalue("title", htdata("title"))                     .addwithvalue("gender", htdata("gender"))                     .addwithvalue("firstname", htdata("firstname"))                     .addwithvalue("lastname", htdata("lastname"))                     .addwithvalue("phone", htdata("phone"))                     .addwithvalue("address", htdata("address"))                     .addwithvalue("email", htdata("email"))                     .addwithvalue("dob", htdata("dob"))                 end                  cmd.executenonquery()             end using         end using          debug.print("the record inserted.")          'if error has occurred, show error message inform user record not inserted     catch ex exception         debug.print("error: " & ex.message)         msgbox("an error occurred. record wasn't inserted.")     end try end sub 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -