-1
cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Steve\Documents\Visual Studio 2010\Projects\Church Of Glory\Church Of Glory\Registry.accdb"
cmd.CommandText = "update Registry set relaship = '" + ComboBox3.Text + "',fathnam = '" + fathnam.Text + "',dob = '" & DateTimePicker1.Value & "',age = '" + age.Text + "',addr = '" + addr.Text + "',area = '" + areas.Text + "',city = '" + city.Text + "',zipc = '" + pinc.Text + "',conta = '" + cnct.Text + "',email = '" + email.Text + "',occup = '" + occu.Text + "',bap_stat = '" + bap_stat + "',bap_dat = '" & DateTimePicker2.Value & "',mar_stat = '" + mar_stat + "',mar_dat = '" & DateTimePicker3.Value & "',gen = 'Male' where fnam = '" + ComboBox2.Text + "' and lnam = '" + ComboBox1.Text + "'"
cmd.Connection = cn
cn.Open()
cmd.ExecuteNonQuery()
MsgBox("Update Successful")
cn.Close()

This code runs perfectly in my system.. but it says

oledb exception was unhandled "data type mismatch"

when i copied the code and executed it in my brother's computer.. i carefully changed the data source path... i'm just a beginner.. all the field type is text except for the dates.. i ve one more field which is an autonumber and i don want that in my update query.. so i left it..

Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
  • Concatenating strings to form sql commands is a very dangerous practice. Not only exposes your code to sql injections, but numerous problems arises when one or more of your 'strings' contains invalid characters. I suggest to put here an example of one cmd.CommandText that fails. In the meantime search for Parameterized Queries – Steve Jun 13 '14 at 10:14
  • preview the command.text into a msgbox and compare the results – ooopsoft Jun 13 '14 at 10:52

1 Answers1

0

It's more than likely something to do with the dates. No offence, but that code is very amateurish when it comes to updating a database table.

You should provide better conditioning for the dates; since you mention a difference with another computer, it's usually to do with the date/time formats being different between the two PCs. More common across countries, obviously, but check the date/time formats between the two computers in Control Panel to be sure.

Someone with access to a PC can probably supply a better answer!

Grim
  • 672
  • 4
  • 17