Saturday, 15 June 2013

Insert a record in sql database using vb.net datatable and datarow features -



Insert a record in sql database using vb.net datatable and datarow features -

i trying insert record in sql database using vb.net dataadapter, datatable, , datarow features. utilize next code gives me error:

object reference not set instance of object

imports system.data.sqlclient public class form1 private sub button1_click(byval sender system.object, byval e system.eventargs) handles button1.click dim cn new sqlconnection("data source=.\sqlexpress;initial catalog=drpractice;integrated security=true") dim da new sqldataadapter dim ds new dataset seek cn.open() da.selectcommand = new sqlcommand("select * [emp_tbl]", cn) da.fill(ds) dim dt new datatable dt = ds.tables("emp_tbl") 'error in line(object reference not set instance of object)' dim dr datarow = dt.newrow() dr.item("emp_id") = textbox1.text.trim dr.item("emp_name") = textbox2.text.trim dr.item("salary") = textbox3.text.trim dr.item("age") = textbox4.text.trim dr.item("emp_group") = textbox5.text.trim dt.rows.add(dr) da.update(ds) msgbox("record inserted") grab ex exception msgbox(ex.message) end seek end sub end class

check out : dim dr datarow = new dt.newrow()

sql vb.net

No comments:

Post a Comment