Updating msacces database

Discussion in 'C#' started by ZyON135, May 14, 2009.

  1. #1
    I wrote this code in asp.net(vb):

    dim dbconn as New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & server.mappath("../kri1.mdb"))
    Dim DBCmd As New OleDbCommand
    Dim DBAdap As New OleDbDataAdapter
    DBCmd = New oledbCommand("INSERT INTO tabela (@id, @nesto, @ime)", DBConn)
    DBCmd.Parameters.Add("@ID", OleDbType.smallint).value= 6
    DBCmd.Parameters.Add("@nesto", OleDbType.varchar ).Value = "2"
    DBCmd.Parameters.Add("@ime", OleDbType.varchar ).Value = "3"
    DBCmd.Connection.Open()
    DBCmd.ExecuteNonQuery()

    and nothing happened in my database and there's no compilation error, pls help
    thx anyway
     
    ZyON135, May 14, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    It might be in your SQL query...
    it should be in the format of:
    "INSERT INTO TableName (Field1, Field2, Field3) Values (@param1, @param2, @param3)"
     
    camjohnson95, May 14, 2009 IP
  3. nikes

    nikes Peon

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    There is no need of OleDbDataAdapter.I think your sql query is incorrect.
    DBCmd = New oledbCommand("INSERT INTO tabela(Cloum list) values (@id, @nesto, @ime)", DBConn)


    -----------------------------------
    .net Tips and Database Connectivity
     
    nikes, May 18, 2009 IP