Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

.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 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -