Datagridview save changes to Database vb.net

后端 未结 3 803
遥遥无期
遥遥无期 2020-12-11 22:47

Hello i\'ve a databse that i load to Datagridview in vb.net application. it loads fine, however when i try to save the date it doesn\'t work. here is the code



        
3条回答
  •  时光说笑
    2020-12-11 23:02

    So you must define an InsertCommand for you DataAdapter

    Side-note: The line DSet.AcceptChanges() is redundant since the previous line Dadapter.Update will call AcceptChanges implicitely.

    You should use using-statement for anything implementing IDisposable like a Connection. That would call Dispose(which closes the connection) implicitely even in case of an exception.

    So replace:

    con.Open()
    Dadapter.Update(DSet, "Table1")
    DSet.AcceptChanges()
    con.Close()
    

    with

    Using con =  New OleDbConnection(myConString)
        con .Open()
        Dadapter.Update(DSet, "Table1")
    End Using
    

提交回复
热议问题