免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3628 | 回复: 4
打印 上一主题 下一主题

asp+sql的问题,请高手帮忙 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2002-01-15 13:30 |只看该作者 |倒序浏览
    一个数据库,比如说叫protable,他含有两个表,aaa和bbb。我有一个表单的填写,要分别插入aaa 和bbb中,但是bbb中有一个记录是要根据aaa刚才插入的记录中自动生成的id来写的。所以我这样写:
Set conn = Server.CreateObject(\"ADODB.Connection\"   
        conn.Open
  \'然后读取表单内容,比如:
sg_name = trim(Request(\"g_name\")
   \'然后更新表aaa
    sqlinsorder = \"insert into aaa  (firstname) values (\'\"& sg_name &\"\')\"
               conn.execute sqlinsorder
\'然后重新打开表aaa,读id的值
sql=\"select orderid from aaa\"
               Set rs= Server.CreateObject(\"ADODB.Recordset\"  
               rs.open sql,conn,3,3
          sOrderid = rs(\"orderid\"
               rsOrder.close
\'然后再把sorderid写入表bbb
sqlinsorderProd = \"insert into bbb (orderid) values (\'\"& sOrderid &\"\')\"
               conn.execute sqlinsorderProd  

可是不对。提示说服务器错误,该页无法显示,请高手帮我看看哪里错了。多谢大家。

论坛徽章:
0
2 [报告]
发表于 2002-01-15 14:15 |只看该作者
报的是哪一行错误?
conn.Open
后面有连接字串吗?

论坛徽章:
0
3 [报告]
发表于 2002-01-15 17:49 |只看该作者
Public Function CS_AddAuction(strProductID As String, strProductName As String, _
    strProductDesc As String, lngUpsetPrice As Long, lngQuantity As Long, strRule As String, _
    strIssueBy As String, dtmStartDate As Date, dtmInvalidDate As Date, _
    lngIsOrderEnd As Long, lngIssueMode As Long, Optional strApplyTo As String = \"\" As Long


    Dim conDbLegend As ADODB.Connection
    Dim strT_Auction As String
    Dim lngAuction_ID As Long
    Dim recAuction As ADODB.Recordset
    Dim ojbCommon As LegendPublic.common
    Dim lngIsAuctionID As Long
    Dim strDept_ID As String
    Dim strSql As String
    Dim rs As ADODB.Recordset
    Dim blnIstrans As Boolean
    Dim strEndTime As String
    Dim dtmEndTime As Date
   
    On Error GoTo cs_addauctionerror
        \'数据库连接
        Set conDbLegend = New ADODB.Connection
        conDbLegend.Open strConString
        
        \'
        Set rs = New ADODB.Recordset
        strSql = \" SELECT DEPT_ID\" _
                & \" FROM CS_DEPT_REF \" _
                & \" WHERE CS_ID = \'\" & strIssueBy & \"\'\"
      
        \'SqlStr = \"select T_BidOrder.Auction_ID, Product_ID, ProductName,UpsetPrice,Order_ID, Agent_ID,Bidding, T_BidOrder.Quantity AS quantity from T_Auction,T_BidOrder where T_Auction.auction_id=T_BidOrder.auction_id and T_bidorder.Order_Id=\" & lOrderId
        rs.Open strSql, conDbLegend, adOpenStatic, adLockReadOnly
        If rs.RecordCount <> 1 Then
             CS_AddAuction = -2
             Set rs = Nothing
             Set conDbLegend = Nothing
             Exit Function
        End If
        
        
        strDept_ID = rs(\"DEPT_ID\"
        Set rs = Nothing
        
        conDbLegend.BeginTrans  \'开始事务
        blnIstrans = True
        strEndTime = CStr(dtmInvalidDate) & \" 23:59:59\"
        dtmEndTime = CDate(strEndTime)
        \'
        \'拍卖商品库新增拍卖(T_Auction)
        Set recAuction = New ADODB.Recordset
        recAuction.CursorLocation = adUseClient
        recAuction.Open \"T_Auction \", conDbLegend, adOpenDynamic, adLockOptimistic, adCmdTable
        recAuction.AddNew
        recAuction(\"roduct_Id\" = strProductID
        recAuction(\"DEPT_ID\" = strDept_ID
        recAuction(\"roductName\" = strProductName
        recAuction(\"roductDesc\" = strProductDesc
        recAuction(\"UpsetPrice\" = lngUpsetPrice
        recAuction(\"Quantity\" = lngQuantity
        recAuction(\"IssueMode\" = lngIssueMode
        recAuction(\"roductRule\" = strRule
        recAuction(\"IssueBy\") = strIssueBy
        recAuction(\"StartDate\") = dtmStartDate
        recAuction(\"InvalidDate\") = dtmEndTime
        recAuction(\"IsOrderEnd\") = lngIsOrderEnd
        recAuction(\"IssueDate\") = Now()
        recAuction.Update
        lngAuction_ID = recAuction(\"Auction_ID\")    \'得到新增记录的Auction_ID值
        
        \'recAuction.Close
        recAuction.ActiveConnection = Nothing
        Set recAuction = Nothing
        
        Set ojbCommon = New LegendPublic.common
        
        lngAuction_ID = ojbCommon.CS_AddToACL(conDbLegend, lngIssueMode, 2, lngAuction_ID, strApplyTo)
        If lngAuction_ID < 0 Then
            conDbLegend.RollbackTrans
            CS_AddAuction = -1
            Set ojbCommon = Nothing
            conDbLegend.Close
            Set conDbLegend = Nothing
            Exit Function
        End If
        
        conDbLegend.CommitTrans \'提交事务
        
        blnIstrans = False
        CS_AddAuction = 1
        Set ojbCommon = Nothing
        conDbLegend.Close
        Set conDbLegend = Nothing
        Exit Function
\'出错处理
cs_addauctionerror:
     If blnIstrans Then
        conDbLegend.RollbackTrans  \'撤销事务
     End If
     CS_AddAuction = -1
     If Not conDbLegend Is Nothing Then
        conDbLegend.Close
        Set conDbLegend = Nothing
     End If
            
     Select Case Err.Number
       Case Else
       Err.Raise Err.Number
     End Select
     
   
End Function

论坛徽章:
0
4 [报告]
发表于 2002-01-15 22:43 |只看该作者
根本就不能显示。只是说服务器内部错误。什么500什么的。
zhlbiti : 我不明白你的意思呢

论坛徽章:
0
5 [报告]
发表于 2002-01-16 15:50 |只看该作者
估计可能是你的连接数据库出错了
在你的程序中我没有看到数据库的连接字串
请你写出来
另外
你可以用response.flush
response.write
显示出错误来!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP