asp中一次更新datagrid中所有记录
要对datagrid中要更新的列建立模版列,比如:
asp:datagrid id="dgpopularfaqs" runat="server"
autogeneratecolumns="false"
...>
itemstyle-horizontalalign="center" headertext="faq id" />
text="<%# container.dataitem("description") %>" />
text="<%# container.dataitem("submittedbyname") %>" />
之后,对datagrid进行一次遍历,
dim myconnection as new sqlconnection(connection string)
dim mycommand as new sqlcommand(strsql, myconnection)
dim dgi as datagriditem
for each dgi in dgpopularfaqs.items
"read in the primary key field
dim id as integer = convert.toint32(dgpopularfaqs.datakeys(dgi.itemindex))
dim question as string = ctype(dgi.findcontrol("txtdescription"), textbox).text
dim submittedby as string = ctype(dgi.findcontrol("txtsubmittedby"), textbox).text
"issue an update statement...
dim updatesql as string = "update tablename set question = @question, " & _
"submittedbyname = @submittedbyname where faqid = @id"
mycommand.parameters.clear()
mycommand.parameters.add("@question", question)
mycommand.parameters.add("@submittedbyname", submittedby)
mycommand.executenonquery()
next
-
相关文章
2秒记住本站域名
玩过泡泡龙吗?Readygo?Go! 再加上.Com.Cn的后缀,那就是大名小顶的ReadyGo.com.cn
