各位大老幫幫手啦﹗

caifang982095 2003-07-29 03:49:28
我在做更新數据的程序時﹐碰到以下問題﹐還請各位大老幫忙解決﹕在更新時﹐不能在空表PONOTES中插入數据﹐要是在PONOTES表中加入几個DOCNO字段值﹐則可以在PONOTES表中插入VENNOTES的字段值﹔現在怎么樣才可以解決這個問題﹒請各位大老提點提點﹗<%@ import namespace="system.data"%>
<%@ import namespace="system.data.sqlclient"%>
<html>
<script language="vb" runat="server">
Sub page_load(sender as object,e as eventargs)
lblSupplierName.text=session("SuppilerName")

IF not (isPostBack)
CALL bindgrid()
END IF
End Sub
Sub bindgrid
Dim cnnConnection As New SqlConnection()
cnnConnection.ConnectionString=ConfigurationSettings.AppSettings("JDE")
cnnConnection.Open()
Dim cmdSQL As New SqlCommand()
cmdSQL.Connection = cnnConnection
cmdSQL.Commandtext ="select * from vopenpo left join ponotes on ponotes.docno=vopenpo.docno where vopenpo.vencode=" & session("userid") & " order by line_no,shipdate"
dim dr as sqldatareader=cmdSQL.executereader()
grdPO.datasource=dr
grdPO.databind()
cnnConnection.close()
end Sub

'編輯
sub datagrid_editcommand(sender as object,e as datagridcommandeventargs)
grdpo.edititemindex=e.item.itemindex
bindgrid()
end sub

'取消
sub datagrid_cancelcommand(sender as object,e as datagridcommandeventargs)
grdpo.edititemindex=-1
bindgrid()
end sub

'更新
sub datagrid_updatecommand(sender as object,e as datagridcommandeventargs)
dim vennotes as string=ctype(e.item.cells(11).controls(0),textbox).text
dim strsql as string
dim insert as string
strsql="update ponotes set vennotes=" & vennotes & " where " & grdpo.datakeyfield & "=" & grdpo.datakeys(e.item.itemindex) & ""
response.write(strsql)
dim strinsert as string
strinsert="insert ponotes (docno,vennotes) values (" & grdpo.datakeys(e.item.itemindex) & "," & vennotes & ")"
response.write(strinsert)
dim cnnconnection as new sqlconnection()
cnnConnection.ConnectionString=ConfigurationSettings.AppSettings("JDE")
cnnconnection.open()
dim cmdcommand as new sqlcommand(strsql,cnnconnection)
cmdcommand.executenonquery
grdpo.edititemindex=-1
bindgrid()
cnnconnection.close()
end sub
</script>
<body background="#6699cc">
<form runat="server">
<h3><font face="宋体">未完成訂單查詢</font></h3>
<I><Asp:Label Runat="Server" Id="lblSupplierName" ForeColor="Red" font-size="16pt"/>
<br></br>
<asp:datagrid id="grdPO" runat="server"
width="700pt"
backcolor="#ccccff"
borderfooter="false"
cellpadding="3"
cellspacing="0"
font-face="宋体"
font-size="12pt"
datakeyfield="docno"
oneditcommand="datagrid_editcommand"
oncancelcommand="datagrid_cancelcommand"
onupdatecommand="datagrid_updatecommand"
headerstyle-backcolor="#ff9933"
autogeneratecolumns="false"
allowsorting="true"
alternatingitemstyle-backcolor="#eeeeff">
<headerstyle backcolor="#ff9900" forecolor="#ffffff" horizontalalign="center" font-bold="true" font-size="10pt" width="100pt"/>
<pagerstyle backcolor="#ff9933" forecolor="#330099" width="100pt" />
<itemstyle backcolor="#ffffff" forecolor="#330099" font-size="9pt" width="100pt" />
<columns>
<asp:editcommandcolumn edittext="編輯" canceltext="取消" updatetext="更新" headertext="功能"/>
<asp:boundcolumn headertext="交貨日期" datafield="shipdate" dataformatstring="{0:dd/MM/yy}" readonly="true"/>
<asp:boundcolumn headertext="訂單類型" datafield="doctype" readonly="true"/>
<asp:boundcolumn headertext="訂單號" datafield="docno" readonly="true"/>
<asp:boundcolumn headertext="行號" datafield="line_no" readonly="true"/>
<asp:boundcolumn headertext="訂單日期" datafield="podate" dataformatstring="{0:dd/MM/yy}" readonly="true"/>
<asp:boundcolumn headertext="款號" datafield="itemno2" readonly="true"/>
<asp:boundcolumn headertext="訂單說明一" datafield="podesc1" readonly="true"/>
<asp:boundcolumn headertext="數量" datafield="poqty" readonly="true"/>
<asp:boundcolumn headertext="單位" datafield="pduom" readonly="true"/>
<asp:boundcolumn headertext="訂單說明二" datafield="podesc2" readonly="true"/>
<asp:boundcolumn headertext="備注" datafield="vennotes"/>
<asp:templatecolumn>
<itemtemplate>
<a href="http://192.168.1.240/testing/displaypic.aspx?id=<%#container.dataitem("itemno1")%>&code=<%#container.dataitem("imtype1")%>" textfield="款號"><%# container.dataitem("itemno2")%></a>
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
</form>
</body>
</html>





...全文
23 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
caifang982095 2003-07-31
  • 打赏
  • 举报
回复
沒有表間約束啊﹗﹗現在能夠更新插入﹐但是再次更新一條紀錄的時候﹐它會又插入一條紀錄﹗很幾啊﹗老板天天在催﹗﹗
sin360 2003-07-29
  • 打赏
  • 举报
回复
检查数据库结构,是否有表间约束

62,133

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧