源程序:<%@ Page Language="VB" %>
<%@ import Namespace="system.data" %>
<%@ import Namespace="system.data.oledb" %>
<%@ import Namespace="system.web.security" %>
<script runat="server">    sub page_load()
        dim strcnndepart as string="provider=microsoft.jet.oledb.4.0;" & _
                                   "data source=d:\meeting\m3r.mdb"
    
        dim cnndepart as new oledbconnection(strcnndepart)
        dim strsqldepart as string="SELECT tblDepartment.DepartID, tblDepartment.Department_Cn " & _
                                    "FROM tblDepartment"
        dim cmddepart as new oledbcommand(strsqldepart,cnndepart)
    
        cnndepart.open()
        drpdldepartment.datasource=cmddepart.executereader(commandbehavior.closeconnection)
        drpdldepartment.databind()
    
    
        'test.datasource=cmdlogin.executereader(commandbehavior.closeconnection)
        'test.databind()
    
        account.text=user.identity.name
    
    
        'add user's detail to the table
    
    
    end sub
    
    Sub LoginBtn_Click(Sender As Object, E As EventArgs)
        dim strcnn as string
        dim strsql as string
        dim objdataset as new dataset()
        dim objcnn as oledbconnection
        dim objadapter as oledbdataadapter
    
     ' set the connection and query details
     strcnn="provider=microsoft.jet.oledb.4.0;" & _
            "data source=d:\meeting\m3r.mdb"
     strsql="SELECT tblaccount.Accountid, tblaccount.Accountname FROM tblaccount "& _
                "WHERE (((tblaccount.Accountname)='" & user.identity.name & "'))"
     'open the connection and set the command
     objcnn=new oledbconnection(strcnn)
     objadapter=new oledbdataadapter(strsql,objcnn)
    
    
     'fill the dataset with the data
     objadapter.fill(objdataset,"tblaccount")
    
     'add new row to the table
     dim objtable as datatable
     dim objnewrow as datarow
    
     objtable=objdataset.tables("tblaccount")
     objnewrow=objtable.newrow()
     objnewrow("accountname")=user.identity.name
     objtable.rows.add(objnewrow)
    
     'generate the update commands
     dim objbuilder as oledbcommandbuilder
    
     objbuilder=new oledbcommandbuilder(objadapter)
     objadapter.updatecommand=objbuilder.getupdatecommand()
     objadapter.insertcommand=objbuilder.getinsertcommand()
     objadapter.deletecommand=objbuilder.getdeletecommand()
     'update the data store
    
     objadapter.update(objdataset,"tblaccount")
    
     'get the accounid
  

解决方案 »

  1.   

    strsql="SELECT tblaccount.Accountid, tblaccount.Accountname FROM tblaccount "& _
                    "WHERE (((tblaccount.Accountname)='" & account.text & "'))"
         objcnn.open
         dim objcmd as new oledbcommand(strsql,objcnn)
         dim objdatareader as oledbdatareader
         dim accountIDnmb as string
         objdatareader=objcmd.executereader()
         accountidnmb=objdatareader("accountid")
         objdatareader.close
        
         'objdatareader=nothing
        
         'get the departid
         dim departidnmb as string
         strsql="SELECT tblDepartment.DepartID, tblDepartment.Department_Cn " & _
                "FROM tblDepartment WHERE (((tblDepartment.Department_Cn)='" & request.form("drpdldepartment") & "'))"
         objcmd=new oledbcommand(strsql,objcnn)
        
        
         objdatareader=objcmd.executereader()
         departidnmb=objdatareader("departid")
        
         objdatareader.close
         'objdatareader=nothing
         objcnn.close
        
         ' insert the new data into the tblemployee
         'open the connection and set the command
         strsql="SELECT tblEmployee.AccountID, tblEmployee.DepartID, tblEmployee.FirstName_Cn, tblEmployee.LastName_Cn, tblEmployee.Extension, tblEmployee.Email " & _
                "FROM tblEmployee WHERE (((tblEmployee.FirstName_Cn)='" & firstname.text & "') AND ((tblEmployee.LastName_Cn)='" &lastname.text &"'))"
        
         objadapter=new oledbdataadapter(strsql,objcnn)
        
        
         'fill the dataset
         objadapter.fill(objdataset,"tblemployee")
         objtable=objdataset.tables("tblemployee")
         objnewrow=objtable.newrow()
         objnewrow("firstname_cn")=firstname.text
         objnewrow("lastname_cn")=lastname.text
         'objnewrow("departid")=departidnmb
         'objnewrow("accountid")=accountidnmb
         objnewrow("email")=email.text
         objnewrow("extension")=extension.text
         objtable.rows.add(objnewrow)
        
         'update the data
         objbuilder=new oledbcommandbuilder(objadapter)
         objadapter.updatecommand=objbuilder.getupdatecommand()
         objadapter.insertcommand=objbuilder.getinsertcommand()
         objadapter.deletecommand=objbuilder.getdeletecommand()
        
         objadapter.update(objdataset,"tblemployee")
        
        
        
        
                    'Msg.Text = "Invalid Credentials: Please try again"
        
        End Sub
        
        'Sub Dropdownlist1_SelectedIndexChanged(sender As Object, e As EventArgs)
        
        'End Sub
        
        Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
        
        End Sub</script>
    <html>
    <head>
    </head>
    <body style="FONT-FAMILY: arial">
        <form runat="server">
            <h2>为了便于管理,请登记个人信息 
            </h2>
            <hr size="1" />
            <table>
                <tbody>
                    <tr>
                        <td>
                            名&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 字:</td>
                        <td>
                            <asp:TextBox id="firstName" runat="server"></asp:TextBox>
                        </td>
                        <td>
                            <asp:RequiredFieldValidator id="Requiredfieldvalidator1" runat="server" ErrorMessage="*" Display="Static" ControlToValidate="firstName"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 氏:</td>
                        <td>
                            <asp:TextBox id="lastname" runat="server"></asp:TextBox>
                        </td>
                        <td>
                            <asp:RequiredFieldValidator id="Requiredfieldvalidator2" runat="server" ErrorMessage="*" Display="Static" ControlToValidate="lastname"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            部&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 门:</td>
                        <td>
                            <asp:DropDownList id="Drpdldepartment" runat="server" OnSelectedIndexChanged="Dropdownlist1_SelectedIndexChanged" datavalue="Departid" datatextfield="Department_cn" Width="160px"></asp:DropDownList>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            分 机&nbsp;&nbsp;号:</td>
                        <td>
                            <asp:TextBox id="extension" runat="server"></asp:TextBox>
                        </td>
                        <td>
                            <asp:RequiredFieldValidator id="RequiredFieldValidator4" runat="server" ErrorMessage="*" Display="Static" ControlToValidate="extension"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Email:</td>
                        <td>
                            <asp:TextBox id="email" runat="server"></asp:TextBox>
                        </td>
                        <td>
                            <asp:RequiredFieldValidator id="RequiredFieldValidator5" runat="server" ErrorMessage="*" Display="Static" ControlToValidate="email"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td>
                        </td>
                        <td>
                            <asp:TextBox id="account" runat="server" Visible="False"></asp:TextBox>
                        </td>
                        <td>
                            <asp:RequiredFieldValidator id="RequiredFieldValidator6" runat="server" ErrorMessage="*" Display="Static" ControlToValidate="account"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                </tbody>
            </table>
            <p>
            </p>
            <p>
            </p>
            <p>
                <asp:button id="LoginBtn" onclick="LoginBtn_Click" runat="server" text="确认"></asp:button>
            </p>
            <p>
                <asp:Label id="Msg" runat="server" ForeColor="red"></asp:Label>
            </p>
            <p>
            </p>
        </form>
    </body>
    </html>
      

  2.   

    谢谢你的回复,问题是为什么我读不到我的表tblaccount(accountid,自动增量,accountname,文本)accountid的值。我不知道是怎么回事,有人说Access有这个问题。