Post your codes and problems where from we can help you to solve your problem.

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

Why gg.Dispose() ??

fro my opinion from there your problem has been arised.

Split the sentence with space and store it in an array then convert to proper case of the first and last element of that array. After that join the array elements with space.

Group By clasue always produce a count or summation of another field. It never shows other feilds, if you tried to so the values of other fields without aggregating them it shows an error message.

If you want to group by with a single field you only can get the aggregated fields. The syntax should be

select p.prtgst,sum(prd.totaltaxamt)As Rate,sum(prd.TaxableAmt)As Taxable_Amount
        from TBL_pur_inv as pr
        INNER JOIN tbl_party_ldg  AS p   ON pr.partyIDpur = p.partyID
        INNER JOIN TBL_pur_invdet  AS prd   ON pr.purinvid = prd.purinvid
        where prd.purinvdt ='2018-01-04' GROUP BY  prd.pdcgst

But to get every feild values the systax should be

select p.prtgst,p.prtynm,pr.invno,pr.invamt,PR.purinvdt,prd.pdcgst,sum(prd.totaltaxamt)As Rate,sum(prd.TaxableAmt)As Taxable_Amount
        from TBL_pur_inv as pr
        INNER JOIN tbl_party_ldg  AS p   ON pr.partyIDpur = p.partyID
        INNER JOIN TBL_pur_invdet  AS prd   ON pr.purinvid = prd.purinvid
        where purinvdt ='2018-01-04' GROUP BY  prd.pdcgst,p.prtynm,pr.invno,pr.invamt,PR.purinvdt,prd.pdcgst

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

ddanbe commented: Thank you for this info! +15

@Jayanta_1: In a parameterised sql statement you must have to use the parameter before adding/creating the parameter. In your first sql statement you didn't use the parameter into the statement. use of parameterised sql statement is the best practice to prevent your database from sql injections.
The codes should be as @xrj already discussed i.e.

        Dim sql = "select Count(*) from pur_invdet where purinvid=@purinvid"
        Dim cmd = New OleDb.OleDbCommand(sql, cn)
        cmd.Parameters.AddWithValue("@purinvid", TextBox1.Text)
        Dim result As Integer = Convert.ToInt32(cmd.ExecuteScalar())

But do not understand why did not you do the update and save codes for new items in the for loop to run between the listviewitems and the updates should be run for every items and save for new items. So previous veriable you declared as resulthas no proper functionality to check and do your updates /save.

And I do not understand what you want to do. Please explain briefly what you want to save/update for every listview items or store a cumulative value for a item if there has duplicate value if any.

WHERE FLD_ORDER_ID = '" & id & "' IN (SELECT '" & id & "' FROM TBL_ORDERITEM_A15428 GROUP BY '" & id & "' HAVING COUNT(*) > 1 )")

From my opinion in sql statement has problem.
You have used IN predicate. The arithmatic operator equal to i.e. = compares a single value to another single value. In case a value needs to compared to a list of values then the IN predicate is used. The IN predicate helps reduce the need to use multiple OR condition.

Your statement should be


If the job ofthe function run_sql_query() is to populate dataadapter and datatable then it cannot delete a record from the table. So you have to create another function / sub procedure to delete a record.

Your SQL statement is quite right.

There is no mistake to get pid in the textbox. But where the codes in the sub procedure run_sql_query() ? Is there any mistake ? God knows.

You can add a few lines in your codes in refresh_text subprocedure when id is null or whitespace, where you can nothing values to all textboxes and image control.


How could you do your job by uing this. Here your target Form is Form3
Your codes should be


hope it can help you.

What was your target form ? Form3 or Form2. Perfectly determine it.

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
'Check User Exits or Not
If Not UserExists() Then
    MsgBox("User does not exist!")
    Exit Sub

"Check for Login

Here the codes for UserExits() Function

Private Function UserExists() As Boolean
    Dim Result as Boolean = False
        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
    Catch ex As Exception
    End Try

    Return Result
End Function

Now codes for LogInToNext() SubProceedure

    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
        If dr("User_Status")=Active" Then
            If dr("User_Type")="Admin" then
            MessageBox.Show("You Don't Have Permission To Login System At This Time")
Catch ex As Exception
    txtusername.Text = ""
    txtpassword.Text = ""
End Try

Hope it can help you.

Remove two duoble quotation mark at the end of the SQL statement which may the cause to close the session.

Use parameterised query to protect your database from unauthorised SQL injections and also it can help you to use spacial characters in your query.

Dim cmd As New OleDbCommand
sql = "select * from EQUIPOS where NO_VEHICULO = ? and DIA Between ? and ?"
cmd.Parameters.AddWithValue("@vehi", DropDownList2.SelectedValue.ToString)
cmd.Parameters.AddWithValue("@dt1", CDate(TextBox2.Text))
cmd.Parameters.AddWithValue("@dt2", T1)

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

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.

To count record nos. the syntax is

select count(*) from <TableName> Where <Condition>

To get the number of records the syntax is

Dim x as Integer = .ExecuteScalar()
Int x =.ExecuteScalar()

Is con one and only one connection object in your project and already opened it at the time of starting of your application ? If it is, don't open it in every procedure or function because you already opened it at the time of your application has started and close it when you are trying to close your application. (Not recommanded)
If you declared a proceedure lavel connection object and already opened it, don't try to open it another time in that proceedure or if you want to open it further more try to close it first then open it and at the end of that proceedure always try to close it.

Reverend Jim has already give you a lesson how could you use it.

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)
                        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)
                If newpage Then
                    newpage = False
                    mRow += 1
                End If
                y += h
                If y + h > e.MarginBounds.Bottom Then
                    e.HasMorePages = True
                    'mRow -= 1
                    newpage = True
                    Exit Sub
                End If
            mRow = 0
        End With
    End Sub

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

    End Sub
End Class

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

@සශික : Nothing wrong in your codes to print data.
Just alter some lines in your codes.
1) Never declare the variable Dim mRow As Integer = 0 at Event level like PrintPage Event, always declare it at Form level and set its value to 0 at BeginPrint Event.
2) Just modify the codes at line No. 23,24 and 25 like

If newpage then
    newpage = False
    mRow +=1
End If
y += h

Hope it can help you.

Microsoft Ribbon Control is not made for vb or c# .net application. You could not use it directly. You can use it for your wpf application. If you want to use it in vb or c# .net application you must have to create a user control by wpf.

"Dim data() As String = {"box1", "box2", "box3"}"
Here box1,box2,box3 are not the names of the variables, they are string 3 values of the string array data().
You can declare it as
Dim data(2) As String

But to store data in an array by using a loop you can use dynamic array. In every rotation you can redimention it to store New one by using Redim keyword before the array name.

You have wrote a wrong code lines to search usertype at line 16 in the if - end if statement. If dr.Read = True Then
'Wrong searching codes here
End If
You already read data by calling ExecuteReader(). So, why are you calling an another Sal statement? You already have data to check UserType.
The codes should be like this.
If dr.Read = True Then
If adaReader("UserType")="Normal" Then
'Do your jobs here for normal
'Doylur jobs for Admn
End if
'Message here
End If
Hope it can help you.

Agreed with @JamesCherrill.
Using a class object you can do it easily.

There ia an extra space in your sql statement you made find from your uploaded picture. The sqlstatement should be

"SELECT health,strength FROM playerstats WHERE playerid= " & playeridlbl.Text 

Before reading the reader, please check it produces any record or it is blank. A blank reader can produce an exception if you try to read it.

If reader.HasRows() then

    'make a loop here to read reader

End If

Hope it can help you.

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

In 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


Hope it can help you.

newLabel.Text = newLabel.Name

Inspite of this code at line no 9 to show data from table you can use this following codes

newLabel.Text = ds.Tables("room").Rows(i)(ColumnIndex)


new Label.Text=ds.Tables("room").Rows(i)("Column Name")

Hope it can help you

Checking duplicate value on every keystroke when you are entering data to a text box is not a perfect thinking. It will disturb the user when he will try to enter data. From my opinion you can perform the duplicate value checking in TextbOX LostFocus Event instead of TextChanged event.

Conversion from string 'FA15' to type integer is not valid

Please check the feild data types of that table which are not matching with your supplied data types.

My opinion is you can solve your problems most easily if you create two seperate functons one to check Blank Text and another to check duplicate value.
If the function (1) finds the blank text then exit from save. and if the function (2) finds the duplicate value from database then exit from save.

I just here give you an example of a function to check blank text.

 Private Function BlankValues() As Boolean

        If Trim(Me.txtStuName.Text) = "" Then
            MessageBox.Show("Student name is empty.")
            Return False
        End If

        If Trim(Me.txtStuRollNo.Text) = "" Then
            MessageBox.Show("Roll No. is empty.")
            Return False
        End If

        Return True
    End Function

And now an example to check duplicate value

 Private Function SearchDuplicate() As Boolean
        Dim result As Boolean = False

        Dim Conn As System.Data.OleDb.OleDbConnection = New System.Data.OleDb.OleDbConnection(ConnString)
        Dim Cmd As New System.Data.OleDb.OleDbCommand


            Cmd.CommandType = System.Data.CommandType.Text

            Cmd.CommandText = "Select Count(*) From Student Where RollNo = ?"

            Cmd.Parameters.AddWithValue("@EnrollNo", Me.txtStuRollNo.Text)

            Cmd.Connection = Conn

            Dim rd As Integer = Cmd.ExecuteScalar()
            If rd > 0 Then
                result = True
            End If


        Catch ex As Exception
        End Try

        Return result
    End Function

Now time to save new data.

Private sub SaveNewData()

    'First Check for blank value.
    'If it finds blank then Exit sub

    If Not BlankValues() Then

        Exit Sub

    End If

    'Check here for duplicate value
    'i.e. the value already exists in database
    'If it true then exit sub

    If SearchDuplicate() Then
        MessageBox.Show(String.Format("Roll No. {0} already exists.", Me.txtStuRollNo.Text))
        Exit Sub

    End If

    'If everything ...