vb.net - Trying to get a data from sql database: what to enter into textbox -
i have text-box named txtitemcode
, when type item-code text box want to display corresponding data grid-view or text boxes.
but it's not firing code, don't know wrong, search in google , keep change codes , got 1 still not working. pasting code here..
public sub selectitem(byval itemcode string) try sql.opendbconnection() dim strsql string = "select itemcode 'item code',itemname 'item name' tblitemmaster itemcode='itemcode'" 'sqlconn.close() dim da new sqldataadapter(strsql, sql.sqlconn) dim ds new dataset da.fill(ds, "tblitemmaster") dgvpurchaseorder.datasource = ds.tables("tblitemmaster") sql.sqlconn.close() catch ex sqlexception msgbox(ex.message, msgboxstyle.critical, "sql error") catch ex exception msgbox(ex.message, msgboxstyle.critical, "general error") end try end sub
i call class text lostfocus, click , of doubted events, no luck ..
you not passing parameter correctly. try this:
dim strsql string = "select itemcode 'item code',itemname 'item name' " & _ " tblitemmaster itemcode= @itemcode" dim cmd new sqlcommand(strsql, sql.sqlconn) dim ds new dataset cmd.parameters.addwithvalue("itemcode", itemcode) dim da new sqldataadapter(cmd) da.fill(ds, "tblitemmaster")
take @ msdn documentation it.
Comments
Post a Comment