Thursday, 2 July 2015

The data types ntext and varchar are incompatible in the equal to operator

I got an error message from the following sentense.
As far as I studied, this error occured becuase I compared Nvarchar and text. It is not incompatible.

 Dim vSqlStr As String = "SELECT * FROM HRSUSERS WHERE HRSUSERNAME = '" & Me.txtUsername.Text & "' AND HRSPASSWORD = '" & Me.txtPassword.Text & "'"

After I have changed to
Dim vSqlStr As String = "SELECT * FROM HRSUSERS WHERE HRSUSERNAME LIKE '" & Me.txtUsername.Text & "' AND HRSPASSWORD LIKE'" & Me.txtPassword.Text & "'"

It works. :)

Sunday, 28 June 2015

Currency format for listview items in vb.net

For k = 1 To DSDs.Tables(0).Columns.Count - 1
               If k = DSDs.Tables(0).Columns.Count - 1 Then
                 lstrow.SubItems.Add(CDbl(DSDs.Tables(0).Rows(j)k).ToString()).ToString("N2"))
                Else
                            lstrow.SubItems.Add(DSDs.Tables(0).Rows(j)(k).ToString)
                End If

Next

How to set listview column width in vb.net

For i As Integer = 0 To Me.lstList.Columns.Count - 1
            Me.lstList.Columns(i).Width = -2
 Next

If you set -2, the control resizes the columns to fit Data and Header.
If you set -1, it does to fit Only Data.

Date Format for Listview Items in vb.net

Using DSAd As New OleDb.OleDbDataAdapter(cmdStr, con)
            Using DSDs As New DataSet
                DSAd.Fill(DSDs, "TBLDAILYSALES")

                For i As Integer = 0 To DSDs.Tables(0).Columns.Count - 1
                    Me.lstList.Columns.Add(DSDs.Tables(0).Columns(i).ToString)

                Next

                For j As Integer = 0 To DSDs.Tables(0).Rows.Count - 1
                    Dim lstrow As New ListViewItem

                    lstrow.Text = FormatDateTime(DSDs.Tables(0).Rows(j)(0).ToString(), DateFormat.ShortDate)


                    For k = 1 To DSDs.Tables(0).Columns.Count - 1
                        lstrow.SubItems.Add(DSDs.Tables(0).Rows(j)(k).ToString)
                    Next
                    Me.lstList.Items.Add(lstrow)
                Next
            End Using