Thursday, July 2, 2015

Code for asp .net Result publish from MYSQL Database

Imports mysql.Data.MySqlClient
Partial Public Class _Default
    Inherits System.Web.UI.Page
    Dim trow As TableRow
    Dim tcl, tct, rcl As New TableCell
    Dim conn As New MySqlConnection
    Dim a, b As String
    Dim c As Boolean
    Dim i, j, k, t, s, z As Integer
    Dim qry, colqry, fqry As String
    Dim tbdb, dbna As String
    Dim dbre, tbcol, fcol, tb_db, db_tb_na As MySqlDataReader
    Dim ta(100) As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Label2.Text = ""
        Label4.Text = ""
        Label5.Text = ""
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Label2.Text = ""
        a = TextBox1.Text
        conn = New MySqlConnection("Data Source="";user id="";pwd="";database="";")
        conn.Open()
        Dim cmd, cmd1, cmd2, cmd3, cmd4 As New MySqlCommand
        z = 1

        tbdb = "SELECT COUNT(*) as columns FROM information_schema.TABLES WHERE table_schema='siva'"
        cmd3 = New MySqlCommand(tbdb, conn)
        tb_db = cmd3.ExecuteReader()
        While tb_db.Read
        End While
        k = Val(tb_db("columns"))
        tb_db.Close()

        dbna = "show tables from siva"
        cmd4 = New MySqlCommand(dbna, conn)
        db_tb_na = cmd4.ExecuteReader()
        t = 1
        While db_tb_na.Read
            ta(t) = db_tb_na.Getname(1)
            t = t + 1
        End While
        db_tb_na.Close()

        trow = New TableRow()
        t1.Rows.Add(trow)
        trow.Cells.Add(tct)
        tct.Text = "Subject Code"
        trow.Cells.Add(tcl)
        tcl.Text = "Grade"
        trow.Cells.Add(rcl)
        rcl.Text = "Result"

        j = 1
        While j <= k
            colqry = "SELECT COUNT(*) AS COLUMNS FROM information_schema.columns WHERE table_name='" + ta(j) + "'"
            cmd1 = New MySqlCommand(colqry, conn)
            tbcol = cmd1.ExecuteReader()
            While tbcol.Read
            End While
            i = Val(tbcol("COLUMNS"))
            tbcol.Close()
           
            qry = "select * from " + ta(j) + " WHERE regno='" + a + "'"
            cmd = New MySqlCommand(qry, conn)
            dbre = cmd.ExecuteReader()
            While dbre.Read
            End While
            If dbre.HasRows Then
                z = 0
                Label4.Text = dbre("regno")
                Label5.Text = dbre("name")
                s = 3
                While s < i
                    trow = New TableRow()
                    t1.Rows.Add(trow)
                    tct = New TableCell
                    trow.Cells.Add(tct)
                    tct.Text = dbre.GetName(s)
                    tcl = New TableCell
                    trow.Cells.Add(tcl)
                    tcl.Text = dbre.GetString(s)
                    rcl = New TableCell
                    trow.Cells.Add(rcl)
                    result(tcl.Text)
                    s = s + 1
                End While
            End If
            dbre.Close()
            j = j + 1
        End While
        If z = 1 Then
            Label2.Visible = True
            Label2.Text = "Check Your Register Number " + vbCrLf + " Given Register Number is wrong.....!"
        End If
        conn.Close()
    End Sub
    Public Sub result(ByVal x As String)
        If x = "U" Or x = "AB" Then
            rcl.Text = "RA"
        ElseIf x = "*" Then
            rcl.Text = ""
            tct.Text = ""
            tcl.Text = ""
        Else
            rcl.Text = "P"
        End If
    End Sub


End Class

No comments:

Post a Comment

Followers