Inserting data in mysql using vb.net (n-tier) -


there's can me vb.codes? i'm new in vb.net , want know how add data in mysql database using n-tier in vb.net. may current code in adding data:

data layer:

public function adddata() datatable     dim mycommand string = "insert tblitems values (@itemcode, @itemname, @itemdescription, @itemtype, @itempricing, @itemonstock, @itemprice, @datemod)"     con.open()     dim sda new mysqldataadapter(mycommand, con)     dim dt datatable = new datatable     sda.fill(dt)     return dt end function 

sorry code. don't know how can use in bll , pl. please me. want learn of guys..

ps: sorry english i'm 14 yr old , want learn programming. did research can't find i'm looking for. in advance.

to insert new record in datatable need execute command , provide values sent database table.

you need this.

public function adddata(itmcode string, itmname string.... omitted other values) integer     dim mycommand string = "insert tblitems values " & _                                "(@itemcode, @itemname, @itemdescription, " & _                                "@itemtype, @itempricing, @itemonstock, @itemprice, @datemod)"     con.open()     dim cmd new mysqlcommand(mycommand, con)     cmd.parameters.addwithvalue("@itemcode", itmcode)     cmd.parameters.addwithvalue("@itemname", itmname)     .... other parameters other values insert follow....      dim rowinserted = cmd.executenonquery()     return rowinserted end function 

this requires pass function values through set of variables values added parameter collection of command , execute command.
execution returns number of records inserted/changed/deleted.

notice query doesn't specify field list, need pass values update every single field in underlying datatable exact order.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -