本文介绍了在线检查...请帮助我.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码有问题.
我们有一个数据库名称QuestionBank(SubCode,Question,Opt1,Opt2,Opt3,Opt4,Ans).
我们正面临着分数计数和最后记录的问题.

default.aspx

There is some problem with the code.
We have a database name QuestionBank(SubCode,Question,Opt1,Opt2,Opt3,Opt4,Ans).
We''re facing a problem with marks count and last record.

default.aspx

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div style="height: 496px">

        <asp:TextBox ID="Questionnoinsert" runat="server"></asp:TextBox>
        <br />
        <br />
        <br />
        <br />
        <asp:TextBox ID="Questioninsert" runat="server" TextMode="MultiLine"

            Width="822px"></asp:TextBox>
        <br />
        <br />
        <br />
        <asp:RadioButton ID="Option1insert" runat="server" />
        <br />
        <br />
        <br />
        <asp:RadioButton ID="Option2insert" runat="server" />
        <br />
        <br />
        <br />
        <asp:RadioButton ID="Option3insert" runat="server" />
        <br />
        <br />
        <br />
        <asp:RadioButton ID="Option4insert" runat="server" />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Label ID="ansinsert" runat="server" Text="Selected answer"></asp:Label>
&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="ansinserttext" runat="server"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Label ID="originalans" runat="server" Text="Answer"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:TextBox ID="orignalansinsert" runat="server"></asp:TextBox>
        <br />
        <br />
        <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="Submit" runat="server" Text="Next" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:Button ID="btnNext" runat="server" Text="Next" Visible=false/>

    </div>
    </form>
</body>
</html>



default.aspx.vb



default.aspx.vb

Imports System.Data.SqlClient
Imports System.Data
Imports System.Data.SqlClient.SqlConnection
Imports System.Data.DataSet
Imports System.Data.SqlClient.SqlDataReader


Partial Class _Default
    Inherits System.Web.UI.Page
    Dim adp As SqlDataAdapter
    Dim dat As DataSet
    Dim MyDataset As New DataSet()
    Dim objReader As SqlDataReader
    Dim maxrows As String
    Dim i As Integer
    Dim myConnection As SqlConnection = New SqlConnection("initial catalog=Students; integrated security=True")
    Dim MyAdapter As New SqlDataAdapter("SELECT * FROM QuestionBank where SubCode=007", myConnection)
    Dim SqlCommand1 As New SqlCommand("SELECT * FROM QuestionBank where SubCode=007", myConnection)

    Protected Sub Page_Load() Handles Me.Load
        myConnection.Open()
        displayrecord()
        If Not Page.IsPostBack Then
            Session("Record") = 0
        End If
        If Not Page.IsPostBack Then
            Session("Record1") = 0
        End If
    End Sub
    Private Sub displayrecord()
        SqlCommand1.CommandType = CommandType.StoredProcedure = CommandType.Text
        SqlCommand1.Connection = myConnection
        objReader = SqlCommand1.ExecuteReader()
        objReader.Read()
        Questioninsert.Text = objReader("Question")
        Option1insert.Text = objReader("Opt1")
        Option2insert.Text = objReader("Opt2")
        Option3insert.Text = objReader("Opt3")
        Option4insert.Text = objReader("Opt4")
        objReader.Close()
        'myConnection.Close()

    End Sub


    Protected Sub btnNext_Click() Handles btnNext.Click
        Option1insert.Enabled = True
        Option2insert.Enabled = True
        Option3insert.Enabled = True
        Option4insert.Enabled = True
        Option1insert.Checked = False
        Option2insert.Checked = False
        Option3insert.Checked = False
        Option4insert.Checked = False
        ansinserttext.Text = ""
        orignalansinsert.Text = ""
        i = i + 1
        'Dim myConnection As SqlConnection = New SqlConnection("initial catalog=Students; integrated security=True")
        'Dim MyAdapter As New SqlDataAdapter("SELECT * FROM QuestionBank where SubCode=007", myConnection)



        MyAdapter.Fill(MyDataset)

        Dim rec_count As Integer = Session("Record")

        Dim row_count As Integer = MyDataset.Tables(0).Rows.Count - 1

        Response.Write(row_count.ToString())
        If rec_count <> row_count Then

            Session("Record") = rec_count

            rec_count = rec_count


            Questioninsert.Text = MyDataset.Tables(0).Rows(rec_count).Item(1)
            Option1insert.Text = MyDataset.Tables(0).Rows(rec_count).Item(2)
            Option2insert.Text = MyDataset.Tables(0).Rows(rec_count).Item(3)
            Option3insert.Text = MyDataset.Tables(0).Rows(rec_count).Item(4)
            Option4insert.Text = MyDataset.Tables(0).Rows(rec_count).Item(5)


        Else
            MsgBox("Last record")

        End If



    End Sub

    Protected Sub Submit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Submit.Click
        If Option1insert.Checked Then
            ansinserttext.Text = Option1insert.Text
            Option2insert.Enabled = False
            Option3insert.Enabled = False
            Option4insert.Enabled = False

        ElseIf Option2insert.Checked Then
            ansinserttext.Text = Option2insert.Text
            Option1insert.Enabled = False
            Option3insert.Enabled = False
            Option4insert.Enabled = False
        ElseIf Option3insert.Checked Then
            ansinserttext.Text = Option3insert.Text
            Option2insert.Enabled = False
            Option1insert.Enabled = False
            Option4insert.Enabled = False
        ElseIf Option4insert.Checked Then
            ansinserttext.Text = Option4insert.Text
            Option2insert.Enabled = False
            Option3insert.Enabled = False
            Option1insert.Enabled = False
        Else
            MsgBox("Select the answer")
        End If

        'Dim myConnection As SqlConnection = New SqlConnection("initial catalog=Students; integrated security=True")
        'Dim MyAdapter As New SqlDataAdapter("SELECT * FROM QuestionBank where SubCode=007", myConnection)


        MyAdapter.Fill(MyDataset)

        Dim rec_count As Integer = Session("Record")

        Dim row_count As Integer = MyDataset.Tables(0).Rows.Count - 1

        Response.Write(row_count.ToString())
        If rec_count <> row_count Then

        End If

        Session("Record") = rec_count + 1

        rec_count = rec_count + 1
        maxrows = MyDataset.Tables(0).Rows.Count
        'MsgBox(maxrows)
        Dim a As String = increment()
        If a <> maxrows Then
            MsgBox(MyDataset.Tables(0).Rows(rec_count - 1).Item(6))
            'myConnection.Close()

            btnNext_Click()
            i = i + 1
            Dim f As Integer = f + i
        Else
            MsgBox("last record")
        End If



    End Sub
    Public Function increment() As String
        i = i + 1
        Return i
    End Function

End Class

推荐答案

Tanwi写道:

代码有问题.


Tanwi写道:

我们正面临商标计数和最后记录的问题.

We''re facing a problem with marks count and last record.


对您遇到的问题的描述真的很差.


此外,恕我直言,没有人会读大量的代码,而没有对当前程序行为和预期行为的更清晰描述.
我强烈建议您先阅读问题解答和常见问题解答,然后再在此处发布.
:)


Are really poor descriptions of the problem you''re experiencing.


Moreover, IMHO noone would read tons of code without a clearer description of the current program behaviour vs the expected one.
I strongly suggest you reading the Q&A FAQ, before posting again here.
:)


Dim rec_count As Integer = Session("Record")

        Dim row_count As Integer = MyDataset.Tables(0).Rows.Count - 1

        Response.Write(row_count.ToString())
        If rec_count <> row_count Then

            Session("Record") = rec_count

            rec_count = rec_count



您要在这里做什么. Dim rec_count As Integer = Session("Record") and Session("Record") = rec_count互斥语句,因为rec_count不会在任何地方更改.

6)为什么需要此功能?



what you are trying to do here. Dim rec_count As Integer = Session("Record") and Session("Record") = rec_count mutually exclusive statements as rec_count is not changed anywhere.

6)why this function is required?

Public Function increment() As String
        i = i + 1
        Return i
    End Function



而不是简单地i++.

7)Dim row_count As Integer = MyDataset.Tables(0).Rows.Count - 1 and maxrows = MyDataset.Tables(0).Rows.Count ...两个不同变量中的值相同...

8)未使用的变量Dim f As Integer = f + i

仍然...很多冗余和错误.

那么,为什么不清理代码.描述确切的问题. ??? !!!.否则,没人会浪费时间清理代码.



instead of simply i++.

7)Dim row_count As Integer = MyDataset.Tables(0).Rows.Count - 1 and maxrows = MyDataset.Tables(0).Rows.Count ... Same value in two different variables...

8)un used variables Dim f As Integer = f + i

still...a lot of redundancy and errors.

So why don''t you Clean your code. Describe exact problem. ???!!!. Otherwise nobody will waste their time to clean up your code.


这篇关于在线检查...请帮助我.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 21:20