Featured post
.net - SqlCommandBuilder not assigning ConnectionString -
i'm using devexpress xtragrid in layout view edit created database row. code use load data:
public function setdata(byval connstring string, byval tabla string) boolean dim d new datatable dim cmd new sqlcommand try using conn new sqlconnection(connstring) conn.open() cmd.connection = conn m_tabla = tabla if (m_id = "") cmd.commandtext = "select * " & m_tabla else cmd.commandtext = "select * " & m_tabla & " idcaptura = '" & m_id & "'" end if m_adapter = new sqldataadapter(cmd) m_dataset = new dataset() m_adapter.fill(m_dataset, m_tabla) grdmetadata.datasource = m_dataset.tables(m_tabla) return true end using catch ex exception return false end try end function
the database can different client client, afaik can't write update command; i've been investigating issue , conclusion need use sqlcommandbuilder automatically generated.
when user ends editing data, use following snippet update database:
private sub btnaceptar_click(byval sender system.object, byval e system.eventargs) handles btnaceptar.click try dim builder new sqlcommandbuilder(m_adapter) grdlayoutview.closeeditor() grdlayoutview.updatecurrentrow() m_adapter.update(m_dataset, m_tabla) * catch ex exception lblestado.text = ex.message end try end sub
in line marked *, "the connectionstring property has not been initialized" exception. table has primary key column (idcaptura), , can see dataadapter.updatecommand set nothing if put breakpoint in said line.
any idea what's wrong here?
by time second code snippet called, sqlconnection made in first 1 has been disposed of, per using
statement. that's why it's not initialized. you're going have either not dispose of connection there, or create connection second code snippet.
like this, example:
private sub btnaceptar_click(byval sender system.object, byval e system.eventargs) handles btnaceptar.click try using conn new sqlconnection(connstring) ' <--- need connection string somewhere here ' conn.open() m_adapter.updatecommand.connection = conn dim builder new sqlcommandbuilder(m_adapter) grdlayoutview.closeeditor() grdlayoutview.updatecurrentrow() m_adapter.update(m_dataset, m_tabla) * end using catch ex exception lblestado.text = ex.message end try end sub
- Get link
- X
- Other Apps
Comments
Post a Comment