Sql Update Trouble!

  • Thread starter Thread starter boskomihic
  • Start date Start date
B

boskomihic

Guest
Code:
Dim cn As New OleDb.OleDbConnection()
        Dim cm As New OleDb.OleDbCommand()
        cn.ConnectionString = _
        "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=D:\My Documents\Visual Studio Projects\Adresar\Adresar.mdb;Mode=ReadWrite"

        Try
            cn.Open()

            cm.Connection = cn

            cm.CommandText = "UPDATE Podaci SET Podaci.Ime = [@Ime], Podaci.Prezime = [@Prezime], Podaci.Datum = [@Datum], Podaci.Adresa = [@Adresa], Podaci.Fixni = [@Fixni], " & _
            "Podaci.Mobilni = [@Mobilni], Podaci.Email = [@Email], Podaci.Home = [@Home], Podaci.Slika1 = [@Slika1], Podaci.Slika2 = [@Slika2], Podaci.[Note] = [@Note] WHERE (((Podaci.ID)=[@ID]));"
            cm.Parameters.Add(New OleDb.OleDbParameter("@ID", OleDb.OleDbType.VarChar))
            cm.Parameters.Add(New OleDb.OleDbParameter("@Ime", OleDb.OleDbType.VarChar))
            cm.Parameters.Add(New OleDb.OleDbParameter("@Prezime", OleDb.OleDbType.VarChar))
            cm.Parameters.Add(New OleDb.OleDbParameter("@Datum", OleDb.OleDbType.VarChar))
            cm.Parameters.Add(New OleDb.OleDbParameter("@Adresa", OleDb.OleDbType.VarChar))
            cm.Parameters.Add(New OleDb.OleDbParameter("@Fixni", OleDb.OleDbType.VarChar))
            cm.Parameters.Add(New OleDb.OleDbParameter("@Mobilni", OleDb.OleDbType.VarChar))
            cm.Parameters.Add(New OleDb.OleDbParameter("@Email", OleDb.OleDbType.VarChar))
            cm.Parameters.Add(New OleDb.OleDbParameter("@Home", OleDb.OleDbType.VarChar))
            cm.Parameters.Add(New OleDb.OleDbParameter("@Slika1", OleDb.OleDbType.VarChar))
            cm.Parameters.Add(New OleDb.OleDbParameter("@Slika2", OleDb.OleDbType.VarChar))
            cm.Parameters.Add(New OleDb.OleDbParameter("@Note", OleDb.OleDbType.VarChar))

            cm.Parameters("@ID").Value = EditID
            cm.Parameters("@Ime").Value = txtIme.Text
            Debug.WriteLine(txtIme.Text)
            cm.Parameters("@Prezime").Value = txtPrezime.Text
            cm.Parameters("@Datum").Value = txtDatum.Text
            cm.Parameters("@Adresa").Value = txtAdresa.Text
            cm.Parameters("@Fixni").Value = txtFixni.Text
            cm.Parameters("@Mobilni").Value = txtMobilni.Text
            cm.Parameters("@Email").Value = llblEMail.Text
            cm.Parameters("@Home").Value = llblWeb.Text
            cm.Parameters("@Slika1").Value = pic1.Text
            cm.Parameters("@Slika2").Value = pic2.Text
            cm.Parameters("@Note").Value = txtNote.Text
            cm.ExecuteNonQuery()


        Catch ex As Exception
            MsgBox(ex.ToString)
        Finally
            cn.Close()

        End Try
This is my update code.
But, even if I dont get any error message, this code doesnt work anything (everything stays same).
Why?
Whats wrong?
 
Are you sure you need this complex way to do an update? I mean using all these @ variables?
Why not perform a normal SQL update query?
 
This query works fine in Microsoft Access.

What you meen by that "Normal update query"?
 
Since this is ADO.Net, none of us really understand what is going
to make this work. In standard ADO with Access, this would
require using ADOX to use an Update Query as a stored proc. I
have no idea what is involved with ADO.Net.

I am moving this to the ADO.Net forum.
 
A normal update SQL should work. I just assumed the question
was how to use an Access update Query with ADO.Net. Using
Queries is about as close to using a stored proc in SQL Server as
you can get in Access, so it is a good idea if one is considering
upgrading the all to SQL Server down the road, or wants to have
versions for both and change the least code.
 
ZIP FILE

Here is my project.
You will be enable to press Update Link Label when you make same changes.
 
Originally posted by Thinker
If I am reading it correctly, it is to pass parameters to an update
query in Access.
No its not.
Im just saying that when I copy this sql query to Access and start it, it work normal.
 
Originally posted by Thinker
I assume Arnout is referring to an SQL Update statement.
Update TableName Set field1=value1, field2=value2, ... Where
primarykeyfield = keyvalue
But thats same
I tried on that way, but when I didn
 
Back
Top