本文介绍了字段错误中有2个相同的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,程序员,这里有个小问题.如您所见,我的任务是处理两个或两个以上具有不同类别的数据
例子

Hello programmers, got a small problem here. As you see I was tasked to do where there are 2 data or more with diferrent category
Example

 CostCenter   Category                 CourseCode      CourseTitle         SO on....
 123          ABC                      imdead          dying               ...
 123          DEF                      dead            funeral             ...
 123          GEH                      Flower          wew                 ...

 456          ABC                      imdead           dying              ...
 456          DEF                      dead             funeral            ...
456           GEH                      Flower           wew                ...                                   


现在,当我只想显示(123)成本中心上变化的数据时,它不会显示,而是显示具有相同数据的最后一个成本中心的数据
请帮助
这是我的代码


Now when i want to show only the data varied on the cost center of (123) it doesnt show up but instead it shows the data of the last costcenter with the same data
plss help
Here is my code

Imports System.Math
Imports System.Web
Imports System.Data.SqlClient
Imports System.Data
Partial Class PlanvsAct
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (IsPostBack = False) Then
            costcenter()
        End If
    End Sub
    Public Sub costcenter()
        Dim rs As String
        Dim cn As SqlConnection = New SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
        rs = "Select [CostCenter] from [tblDiscipline]"
        cn.Open()
        Dim cmd As SqlCommand = New SqlCommand(rs, cn)
        ddcc.DataSource = cmd.ExecuteReader
        ddcc.DataValueField = "CostCenter"
        ddcc.DataTextField = "CostCenter"
        ddcc.DataBind()
        cn.Close()

    End Sub
    Public Sub categorybind()
        Dim strSQL As String
        Dim connection As SqlConnection = New SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
        strSQL = "Select [Category] from [tblCategory] "
        connection.Open()
        Dim command As New SqlCommand(strSQL, connection)
        ddcategory.DataSource = command.ExecuteReader
        ddcategory.DataTextField = "Category"
        ddcategory.DataValueField = "Category"
        ddcategory.DataBind()
        connection.Close()

    End Sub

    Public Sub coursecodebind()
        Dim strSQL As String
        Dim connection As SqlConnection = New SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
        strSQL = "Select [CourseCode] from tblTrainingPlan where ([Category] LIKE '%' + @Category + '%')"
        connection.Open()
        Dim command As New SqlCommand(strSQL, connection)
        command.Parameters.AddWithValue("@Category", ddcategory.SelectedValue)
        ddcoursecode.DataSource = command.ExecuteReader
        ddcoursecode.DataTextField = "CourseCode"
        ddcoursecode.DataValueField = "CourseCode"
        ddcoursecode.DataBind()
        connection.Close()
    End Sub
    Public Sub binddata()
        Dim strSQL As String
        Dim connection As SqlConnection = New SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
        strSQL = "Select * from [tblTrainingPlan] where ([CourseCode] LIKE '%' + @CourseCode + '%')"
        connection.Open()
        Dim command As New SqlCommand(strSQL, connection)
        command.Parameters.AddWithValue("@CourseCode", ddcoursecode.SelectedValue)
        Dim datareader As SqlClient.SqlDataReader = command.ExecuteReader
        Do While datareader.Read()
            lblid.Text = (datareader("ID").ToString)
            txtTitle.Text = (datareader("CourseTitle").ToString)
            txtcollege.Text = (datareader("College").ToString)
            txtDuration.Text = (datareader("Duration").ToString)
            txtattendees.Text = (datareader("TargetAttendees").ToString)
            txtbatches.Text = (datareader("TotalBatches").ToString)

            a1.Text = (datareader("TH_F_NoAttendeesPerBatch").ToString)
            s1.Text = (datareader("TH_F_NoSessionPerBatch").ToString)
            h1.Text = (datareader("TH_F_NoHoursPerSession").ToString)

            a2.Text = (datareader("TH_MOT_NoAttendeesPerBatch").ToString)
            s2.Text = (datareader("TH_MOT_NoSessionPerBatch").ToString)
            h2.Text = (datareader("TH_MOT_NoHoursPerSession").ToString)

            a3.Text = (datareader("TH_P_NoAttendeesPerBatch").ToString)
            s3.Text = (datareader("TH_P_NoSessionPerBatch").ToString)
            h3.Text = (datareader("TH_P_NoHoursPerSession").ToString)

            pd.Text = (datareader("PerDiem").ToString)
            tr.Text = (datareader("Transportation").ToString)
            ac.Text = (datareader("Accomodation").ToString)
            vm.Text = (datareader("MealVenue").ToString)
            cs.Text = (datareader("Consultant").ToString)
            mt.Text = (datareader("Material").ToString)

            con.Text = (datareader("Contract").ToString)
            am.Text = (datareader("Amount").ToString)

            txtMal.Text = (datareader("MealAllowance").ToString)
            txtTA.Text = (datareader("TransAllowance").ToString)

            tth.Text = (datareader("TotalTrainingHours").ToString)
        Loop
        connection.Dispose()
        connection.Close()
    End Sub



    Public Sub control()
        If ddcoursecode.SelectedValue = "" Then
            txtTitle.Text = ""
            txtcollege.Text = ""
            txtDuration.Text = ""
        End If
    End Sub

    Protected Sub ddcoursecode_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddcoursecode.SelectedIndexChanged
        binddata()

    End Sub

    Protected Sub ddcategory_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddcategory.SelectedIndexChanged
        coursecodebind()
    End Sub

    Public Sub calculationbind()
        Dim x, y, z As Double
        x = Round((CDbl(a1.Text) * CDbl(s1.Text) * CDbl(h1.Text)), 2)
        y = Round((CDbl(a2.Text) * CDbl(s2.Text) * CDbl(h2.Text)), 2)
        z = Round((CDbl(a3.Text) * CDbl(s3.Text) * CDbl(h3.Text)), 2)
        'tth.Text = Round((x + y + z), 2)

        'txtsession.Text = Round((CDbl(s1.Text) + CDbl(s2.Text) + CDbl(s3.Text)), 2)
        'txthour.Text = Round((CDbl(h1.Text) * CDbl(h2.Text) * CDbl(h3.Text)), 2)

        'txtTE.Text = Round((CDbl(txtMal.Text) + CDbl(txtTA.Text) + CDbl(pd.Text) + CDbl(tr.Text) + CDbl(cs.Text) + CDbl(mt.Text) + CDbl(vm.Text) + CDbl(ac.Text)), 2)

    End Sub
    Public Sub calculationbind2()

    End Sub
    Protected Sub ddcc_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddcc.SelectedIndexChanged
        categorybind()
    End Sub
End Class

推荐答案

Select distinct [CostCenter] from [tblDiscipline]



CategoryBind :



CategoryBind:

Select distinct [Category] from [tblCategory] WHERE [CostCenter] = @SELECTED_COSTCENTER



课程绑定:



CourseBind:

Select distinct [CourseCode] from tblTrainingPlan where ([Category] = @Category AND [CostCenter=@SELECTED_COSTCENTER])



BindData :



BindData:

Select * from [tblTrainingPlan] where ([CourseCode] = @CourseCode AND [Category] = @Category AND [CostCenter=@SELECTED_COSTCENTER])




如果有帮助,请将其标记为答案




Mark it as answer if it is helpful


Public Sub binddata()
       Dim strSQL As String
       Dim connection As SqlConnection = New SqlConnection("Data Source=ML0003135586;Initial Catalog=TestSQL;Integrated Security=True")
strSQL = "Select * from [tblTrainingPlan] where ([CourseCode] LIKE '%' + @CourseCode + '%' ) AND ([CostCenter] LIKE '%' + @CostCenter + '%' ) "
       connection.Open()
       Dim command As New SqlCommand(strSQL, connection)
       command.Parameters.AddWithValue("@CostCenter", ddcc.SelectedValue)
       command.Parameters.AddWithValue("@CourseCode", ddcoursecode.SelectedValue)

       Dim datareader As SqlClient.SqlDataReader = command.ExecuteReader
       Do While datareader.Read()


这篇关于字段错误中有2个相同的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 21:47