asp.net - VB.NET updating SQL Database Command -
i building asp.net web application using vb , .net 2.0. have class handles object , attributes. class correctly handles reading, creating, , deleting database. however, not update. took update script straight microsoft sql database, cannot figure out. here sql command.
savecommand = "update [database].[table] set [name] = @name,[content] = @content,[date_updated] = @dateupdated ref = @ref" this beingness set into...
dim setcmd new sqlcommand(savecommand, sqlconn) and parameter values set it. weird because "savecommand" determined on whether item exists (updates) or doesn't (switches "insert into" command works)
more code
public class myclass() #region properties public name string = "" public content string = "" public date_updated datetime = datetime.now #end part public sub save() dim sqlconn new sqlconnection(sqlconnstring) sqlconn.open() dim savecommand string if me.exists savecommand = "update [database].[table] set [name] = @name,[content] = @content,[date_updated] = @date_updated ref = @ref" else savecommand = "insert [database].[table] ([name],[content],[date_updated],[ref]) values(@name,@content,@date_updated,@ref)" end if dim setcmd new sqlcommand(savecommand, sqlconn) setcmd.parameters.add("@name", data.sqldbtype.varchar).value = me.name setcmd.parameters.add("@content", data.sqldbtype.varchar).value = me.content setcmd.parameters.add("@date_updated", data.sqldbtype.datetime).value = me.date_updated if me.exists setcmd.parameters.add("@ref", data.sqldbtype.int).value = me.id else dim countcmd new sqlcommand("select count(*) [dwm-datasql].[dbo].[biglots]", sqlconn) me.id = countcmd.executescalar() + 1 setcmd.parameters.add("@ref", data.sqldbtype.int).value = me.id me.exists = true end if setcmd.executenonquery() sqlconn.close() sqlconn.dispose() end sub public sub new() end sub public sub new(byval num integer) me.id = num end sub end class this beingness called upon by
myobj = new bll.myclass(ref) 'when form submitted public sub submitform(byval sender object, byval e system.eventargs) myobj.name = tbname.text myobj.content = tbcontent.text myobj.save() end sub
i figured out. somehow calling upon read() function right before save() function replaced values. anyway
asp.net sql sql-server vb.net visual-studio-2010
No comments:
Post a Comment