You can do it by using a STRUCTUREwhich can give you full functionality to solve your problem.

Read this post you can get your way to solve the problem by yourself.

ddanbe commented: Nice +15

You can read this overview, which can help you.

No need to use canvas, h.alingment of ellipse should be left.

ddanbe commented: Thank you for this info! +15

Incorrect sql syntax used to update a table.

$sql = "UPDATE users SET Status_To_Public "$db_status_to_public" WHERE Username = '".$user."'";

Use an equal to sign i.e. =to set a value to a field of a table.

$sql = "UPDATE users SET Status_To_Public ="$db_status_to_public" WHERE Username = '".$user."'";

From my opinion you already wrote a code in cmblogintype SelectionChanged event which redirecting you on selection.

Secondly, why are you using loginCommand.ExecuteNonQuery() . You can use it to write data in a table not for reading.
To read use ExecuteReader() method of the command object loginCommand.

Use parameterised query, which can protect your database from unexpected injections and alse you can handle your datatables most easily and efficiently. Like, You do not insert any special charactor to any field a table directly, but using parameterised query you can do it.

I just tried to modify your codes which can help you.

Dim sqlLoginCode As String = "select * from tblusers where User_username = ? AND User_password = ?"

        Dim loginCommand As New OleDb.OleDbCommand(sqlLoginCode)

        loginCommand.Connection = New OleDb.OleDbConnection(connstring)

        If loginCommand.Connection.State = ConnectionState.Open Then loginCommand.Connection.Close()
        loginCommand.Connection.Open()

        'Adding parameters
        loginCommand.Parameters.AddWithValue("@txtuname", txtUsername.Text)
        loginCommand.Parameters.AddWithValue("@txtpwd", txtPass.Text)

        'Declaring data reader to read table rows
        Dim loginreader As OleDbDataReader = loginCommand.ExecuteReader()

        'Before reading check if reader has any row or not
        'if not pass away.
        'If there is a row do something.
        If loginreader.HasRows() Then

            'read data reader
            loginreader.Read()

            'match with field value
            Select Case loginreader("User_usertype")

                Case "Administrator"

                    MessageBox.Show("Welcome Admin")
                    frmAdmin.Show()
                    Me.Hide()

                Case "Teacher"

                    MessageBox.Show("Welcome Admin")
                    frmTeacherForm.Show()
                    Me.Hide()

            End Select

        Else

            MessageBox.Show("Login Failed!!")
            txtUsername.Clear()
            txtPass.Clear()
            txtUsername.Focus()

        End If

For this you donot have to write a macro in excel. You can do it by using IF(<Condition>,True Value,False Value) against a particular cell of the Sheet.

Like

        =IF(A5<DATE(2016,12,22),0,IF((A5>=DATE(2016,12,22))*AND(A5<DATE(2016,12,31)),1,"Invalid Date"))

Thanks

Union Clause
Multiple queries can be put together and their output can be combined using the union clause. The union clause merges the output the output of two or more quries into a single set of rows and columns.

Optput = Records from query 1 + Records from query 2 + a single set of records, common in both queries.

While working with the UNION clause the following pointers should be considered:
1) The number of columns and the data types of the columns being selected must be identical in all the SELECT statements used in the query. The names of the columns need not be identical.
2) UNION operates over all of the columns being selected.
3) NULL values are not ignored during duplicate checking.
4) The IN operator has a higher precedence than the UNION operator.
5) By default, the output is sorted in ascending order of the first column of the SELECT clause.

The restriction on using a union are as follows:
1) Number of columns in all the quries should be the same.
2) The data type of the columns in each query must be same.
3) Unions cannot be used in subquries.
4) Aggregate function cacot be used within union clause.

Your statement should be

select tt from (
    select sum(total_amount) As tt from loan where loan_status = 'not finish' union all
    select sum(amount) As tt from settlement where sett_status = 'Active') x 

Hope it can help you.

Taywin commented: clear explanation +13

You can go through the tables column name . By control flow you can show the textboxs of the respective months.

Quite right, you can use case expression to do that.

Dim courses As String = "jan,mar" I copied it from your post, forgot it to remove , sorry. The above codes which I post written directly in DW. I had no way to examine it in my computer in that moment or to dry run the codes.

Your statement should be

Dim sqlstr as string="Select A.id,"
dim sqlsum as string=""
For i As Integer = 0 To 2
    sqlstr &="(A." & xsql(i) & "+B." & xsql(i) & ") As " & MonthName(i+1) & ","
    sqlsum &= "(A." & xsql(i) & "+B." & xsql(i) & ")" & IIf(i<2,"+","")
Next
sqlstr &= sqlsum & " As Total"
sqlstr &= " From first A Inner Join second B On A.id=B.sid Order By A.id"

You already declared the table 'first' as 'A' and 'second' as 'B'. In SQL statement you must have to specify which 'mar' you are trying to call from databases 'A' or 'B' by prefixing A or B before mar.

Going through a loop you can construct your SQL statement easily.

Dim xsql() As String=split("jan,feb,mar",",")

Dim sqlstr as string="Select A.id,"
For i As Integer = 0 To 2
    sqlstr &="(A." & xsql(i) & "+B." & xsql(i) & ") As " & MonthName(i+1) & Iff(i<2,",","")

Next
sqlstr &= " From first A Inner Join second B On A.id=B.id Order By A.id"

The above example can finally produce the SQL Statement as

Select A.id,(A.jan+B.jan) As January,(A.feb+B.feb) As February,(A.mar+B.mar) As March From first A Inner Join second B On A.id=B.id Order By A.id

Now your final codes should be

con.Open()
        Dim courses As String = "jan,mar"
        Dim cmd As New MySqlCommand
         Dim xsql() As String=split("jan,feb,mar",",")

Dim sqlstr as string="Select A.id,"
For i As Integer = 0 To 2
    sqlstr &="(A." & xsql(i) & "+B." & xsql(i) & ") As " & MonthName(i+1) & Iff(i<2,",","")

Next
sqlstr &= " From first A Inner Join second B On A.id=B.sid Order By A.id"

        cmd.CommandText = sqlstr
        cmd.Connection = con
        Dim rd As MySqlDataReader = cmd.ExecuteReader()
        If rd.HasRows() Then
            Dim x As String
            dim y as integer=0
            Do While rd.Read()
            y +=1
                x &= String.Format("{0}  {1}", rd("id"), rd(MonthName(y)) & vbCrLf

            Loop
            MessageBox.Show(x)
        End If
        rd.Close()
        cmd.Dispose()
        con.Dispose()

Hope it can help you.

You can use the following SQL Statement

Select A.id, 
(A.jan + B.jan) As JANUARY,
(A.feb + B.feb) As FEBRUARY,
(A.mar + B.mar) As MARCH,
(A.apr + B.apr) As APRIL
 From first A 
Inner Join second B
On A.id=B.id Order By A.id
savedlema commented: thank you +2

From my point of view you already complecated your code to check your database and then make permission.

From my point of view first check if there any record exists or not then do the next step.
If there is no record then exit from entire proceedure else try to check priviledge of that user.

If txtpassword.Text = "" Or txtusername.Text = "" Then
    MessageBox.Show("Please Fill in Empty TextBox!")
    Exit Sub
EndIf
'Check User Exits or Not
If Not UserExists() Then
    MsgBox("User does not exist!")
    Exit Sub
EndIf

"Check for Login
LogInToNext()

Here the codes for UserExits() Function

Private Function UserExists() As Boolean
    Dim Result as Boolean = False
    Try
        con.Open()
        Dim query As String
        query = "SELECT Count(*) FROM moneycs.user where User_Name= '" & txtusername.Text & "' and Password = '" & txtpassword.Text & "' "
        cmd = New MySqlCommand(query, con)
        If cmd.ExecuteScalar()>0 then Result=True
        cmd.Dispose()
    Catch ex As Exception
    Finally
        con.close()
    End Try

    Return Result
End Function

Now codes for LogInToNext() SubProceedure

Try
    con.Open()
    Dim query As String
    query = "SELECT User_Type,User_Status FROM moneycs.user where User_Name= '" & txtusername.Text & "' and Password = '" & txtpassword.Text & "' "
    cmd = New MySqlCommand(query, con)
    dr = cmd.ExecuteReader
    if dr.HasRows() Then
        dr.Read()
        If dr("User_Status")=Active" Then
            If dr("User_Type")="Admin" then
                frmmlsadmin.Show()
            Else
                MLSUser.Show()
            Endif
        Else
            MessageBox.Show("You Don't Have Permission To Login System At This Time")
        Endif
    Endif
    dr.Close()
    cmd.Dispose()
Catch ex As Exception
    MessageBox.Show(ex.Message)
Finally
    txtusername.Text = ""
    txtpassword.Text = ""
    con.Close()
    Me.Hide
End Try

Hope it can help you.

Your SQL syntax should be as follows:

Inveupdate.CommandText = "UPDATE tblItems SET Quantity = Quantity - 1 WHERE Barcode=@Barcode"

MsSQl, MySql or Oracle alaways receive named parameter you can use "?" i.e. question mark when you use only OleDb database provider.

Go through this site

sashiksu commented: Where I can find server address ? +1

You must have to add eventhandler to do any job by a dynamic control.

subitem1.DropDownItems.Add(subitem2)
subitem2.Text = "Alle dopen " + col2
AddHandler subitem2.Click, AddressOf Me.Click2

Here Click2 is a userdefined sub procedure, which can perfom on click event of subitem2 submenu.

I just tried your codes in my mechine and I have altered one to two lines you can find them in following codes.

Public Class Form1
    Dim mRow As Integer = 0
    Dim newpage As Boolean = True

    Private Sub PrintDocument1_BeginPrint(sender As Object, e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.BeginPrint
        mRow = 0
        newpage = True
    End Sub

    Private Sub PrintDocument1_PrintPage(sender As System.Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

        With dgvreciept
            Dim fmt As StringFormat = New StringFormat(StringFormatFlags.LineLimit)
            fmt.LineAlignment = StringAlignment.Center
            fmt.Trimming = StringTrimming.EllipsisCharacter
            Dim y As Single = e.MarginBounds.Top
            Do While mRow < .RowCount
                Dim row As DataGridViewRow = .Rows(mRow)
                Dim x As Single = e.MarginBounds.Left
                Dim h As Single = 0
                For Each cell As DataGridViewCell In row.Cells
                    Dim rc As RectangleF = New RectangleF(x, y, cell.Size.Width, cell.Size.Height)
                    e.Graphics.DrawRectangle(Pens.Black, rc.Left, rc.Top, rc.Width, rc.Height)
                    If (newpage) Then
                        e.Graphics.DrawString(dgvreciept.Columns(cell.ColumnIndex).HeaderText, .Font, Brushes.Black, rc, fmt)
                    Else
                        e.Graphics.DrawString(dgvreciept.Rows(cell.RowIndex).Cells(cell.ColumnIndex).FormattedValue.ToString(), .Font, Brushes.Black, rc, fmt)
                    End If
                    x += rc.Width
                    h = Math.Max(h, rc.Height)
                Next
                If newpage Then
                    newpage = False
                Else
                    mRow += 1
                End If
                y += h
                If y + h > e.MarginBounds.Bottom Then
                    e.HasMorePages = True
                    'mRow -= 1
                    newpage = True
                    Exit Sub
                End If
            Loop
            mRow = 0
        End With
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        PrintPreviewDialog1.Document = PrintDocument1
        PrintDocument1.Print()
        PrintPreviewDialog1.Show()

    End Sub
End Class

Hope it can help you. Executing it I got perfect result

hericles is correct.
Firstly you called the function without parameter value.
Secondly codes in function UserExit() need some change. No need to use datareader. Just you have to sure any value exist or not in the table.
I just change in your codes, you can use it if you want. Hope it can help you.

Public Function UserExit(empcode As String) As Boolean
    Dim conn As New MySql.Data.MySqlClient.MySqlConnection
    conn.ConnectionString = appConnectionString
    If conn.State = System.Data.ConnectionState.Closed Then conn.Open()
    Dim cmd As New MySql.Data.MySqlClient.MySqlCommand
    cmd.CommandType = CommandType.Text
    cmd.CommandText = "Select Count(*) From EmMaster Where EmploHba_EmpCode =@empcd"
    cmd.Parameters.AddWithValue("@empcd", empcode)
    cmd.Connection = conn
    Dim Result As Integer = cmd.ExecuteScalar()
    cmd.Parameters.Clear()
    cmd.Dispose()
    conn.Close()
    conn.Dispose()
    If Result > 0 Then
        Return True
    Else
        Return False
    End If
End Function

Private Sub txtEmpCode_LostFocus(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles txtEmpCode.LostFocus
    If UserExit(CType(e.OriginalSource, TextBox).Text) Then
        MessageBox.Show("User Exists. Please input a unique value.")
        CType(e.OriginalSource, TextBox).SelectionStart = 0
        CType(e.OriginalSource, TextBox).SelectionLength = CType(e.OriginalSource, TextBox).Text.Length
    End If
End Sub
Parth_3 commented: ty for help me but +0

Normally every form level events are declared privately. So you can not access them from another form or page . To do this you can create procedure publicly in a module or class and call it from any where in your application.

You can add buttons dynamically and add handler with them to search the appropriate record from database.
The textproperty of the button should be acsdr("tableno").
After clicking the button, serch records on basis of the text property of the button or sender.
Hope it can help you.

You can do it by adding an another condition in Where clause.

Try
            If txtBoxSettingNewPassword.Text = txtBoxSettingConfPassword.Text Then
                con.Open()
                cmd.Connection = con
                cmd.CommandType = System.Data.CommandType.Text
                cmd.CommandText = ("UPDATE [User] " & _
                "SET password = '" & (txtBoxSettingNewPassword.Text) & "'" & _
                "WHERE user_name ='" & (txtBoxSettingUserName.Text) & "' And password = '" & (txtBoxSettingOldPassword.Text) & "'")
                cmd.ExecuteNonQuery()
                MessageBox.Show("password changed successfully")
            Else
                MessageBox.Show("Passwords do not match")
            End If
        Catch ex As Exception
            MessageBox.Show("Something went wrong," & ex.Message)
        Finally
            con.Close()
        End Try

Suppose, it can help you.
You must need a textbox/ variable for old/present password.
Secondly I suggest you to use parameterised query to prevent your database from un authorised SQL Injections.

I have surprised. In morning it was the old, now it is new one.
I like it. Design is cool. A great effort Dani. Keep it up.
In log in page , Login button,s alignment should be right aligned.

Dani commented: Thanks for the suggestion. Change made. +0

Do not understand the need of the codes from line 5 to 15. I can asume that they are not for add button.

You already declare the connection object in line 16. So no need of the lines 18 & 19. You can remove them. Next lines are right to add record into the datatable.

for editing codes are as same as codes for addition of a record except SQL Statement
it should be

sql = "UPDATE inventory SET pcode = @icode, psup = @isup, pcat = @icat, pdescript = @idesc, pstock = @istock, piprice = @iprice, ptprice = @iptprice, pdate = @idate"

Next lines for editing are same.

For deleting sql statement should be

sql = "DELETE FROM inventory WHERE pcode = @icode"
Dim cmd As New OleDb.OleDbCommand(sql, conn)
cmd.Parameters.Add(New OleDb.OleDbParameter("@icode", txtPcode.Text))

cmd.ExecuteNonQuery()
conn.Close()

Hope it can help you.

@Imam_3: Sorry! I overlooked the codes for the Loop.

In vb.net any collection of objects are always 0 base indexed. So to count the total item numbers is always 1 less from the upper bound of that specific collection i.e Collection.count-1. If you have a collection of 10 objects. The index of the first element should be 0 and the index of the Last element should be Collection.Count-1 i.e. 10-1=9. So loop always rotates between 0 to Collection.Count-1
So your loop should be

For i = 0 To ds.Tables("room").Rows.Count-1

'your codes here

Next

Hope it can help you.

Make sure that is the table name customer details contains a space. If this, rename your table name and remove the space, then write the actual table name in the place of "customer details". No need to use dbo. before table name.

Hope it can help you.

It should be
Column_Name like '10%'

The LIKE predicate allows comparison of one string value with another string value, which is not identical. This is achieved by using wildcard characters.
Two wildcard characters are available here.
1) % - allows to match any string of any length(including zero length)
2) _ - allows to match on a single character.

The expression Column_Name like '10%' returns you 10.00, 10.10, 10.20, 10.15 and also all value which starts by '10'.
And the expression Column_Name like '10._0' returns only '10.00'.

Hope it can help you.

GROUP BY tmp.percentage, tmp.product

For this line you can get an error, because percentage column is not included in query.

The Select Statement should be

SELECT tmp.percentage, tmp.product, tmp.location
FROM (
    SELECT *
    FROM mysample
    WHERE location = 'TPJ'
    GROUP BY percentage, product
    HAVING COUNT(*) = 1
) tmp, mysample
WHERE tmp.product = mysample.product
AND mysample.location = 'TPJ'
GROUP BY tmp.percentage, tmp.product
HAVING COUNT(*) > 1;

Hope it can help you.

for which object the exception occured? Here you have three objects, DataGridViewRow, OleDb.OleDbCommand and OleDb.OleDbConnection.
Remove the Try....End Try from loop. Make the loop within Try.

You declare the Command object at Form Level, so imidiate after calling ExecuteNonQuery() method Clear the parameters and dispose the command object. Or you can declare the Command object at Procedure level. From my opinion the codes should be

Public Class frmCreate
    Dim con As New OleDb.OleDbConnection
    Dim cmd As New OleDb.OleDbCommand

    Private Sub btnSave_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        cmd = New OleDb.OleDbCommand

        con = New OleDb.OleDbConnection
        con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Application.StartupPath & "/sale.accdb"
        con.Open()
        cmd.Connection = con
        cmd.CommandText = "INSERT INTO tblProducts([pID], [pName], [pPrice])VALUES(?, ?, ?)"
        cmd.Parameters.AddWithValue("@pID", txtId.Text)
        cmd.Parameters.AddWithValue("@pName", txtName.Text)
        cmd.Parameters.AddWithValue("@pPrice", txtPrice.Text)
        cmd.ExecuteNonQuery()
        cmd.Parameters.Clear()
        cmd.Dispose()
        con.Close()

        txtId.Text = ""
        txtName.Text = ""
        txtPrice.Text = ""

        MsgBox("Record Saved")

        txtId.Focus()

    End Sub
End Class

Hope it can help you.

Structure Gradebook
Dim ID As Integer
Dim Exam1 As Integer
Dim Exam2 As Integer
Dim Exam3 As Integer
Dim Avgg As Integer
Dim LG As Char
End Structure

This is the Structure you declared. I just made a little change inyour structure which can give you your desired result. It should be

Structure Gradebook
        Dim ID As String        'Should be String Type
        Dim Exam1 As String
        Dim Exam2 As String
        Dim Exam3 As String
        Dim Avgg As String
        Dim LG As String

        Public Overrides Function ToString() As String
            Return String.Format("{0}{1}{2}{3}{4}{5}", {getString(ID), getString(Exam1), getString(Exam2), getString(Exam3), getString(Avgg), LG})
        End Function

        Private Function getString(ByVal str As String) As String
            'Function to get a fixed length string

            Dim cnt As Integer
            cnt = 20 - Len(Trim(str))

            Return str.PadRight(cnt) & vbTab
        End Function
End Structure

The result you can get Capture1.PNG

The full code snippet is

Public Class Form1

    Dim index As Integer = 0
    Structure Gradebook
        Dim ID As String        'Should be String Type
        Dim Exam1 As String
        Dim Exam2 As String
        Dim Exam3 As String
        Dim Avgg As String
        Dim LG As String

        'Public Overrides Function ToString() As String
        'Return String.Format("{0}{1}{2}{3}{4}{5}", {ID.PadRight(12) & vbTab, Exam1.PadRight(10) & vbTab, Exam2.PadRight(10) & vbTab, Exam3.PadRight(10) & vbTab, Avgg.PadRight(5) & vbTab, LG})
        'End Function

        Public Overrides Function ToString() As String
            Return String.Format("{0}{1}{2}{3}{4}{5}", {getString(ID), getString(Exam1), getString(Exam2), getString(Exam3), getString(Avgg), LG})
        End Function

        Private Function getString(ByVal str As String) As String
            'Function to get a fixed length string

            Dim cnt As Integer
            cnt = 20 - Len(Trim(str))

            Return ...
Reverend Jim commented: Nice example. +12