i have listview named : listview1 and a button to export listview data presented. all i want is to export that data to an excel probably to edit or print them. Is there anyone can help me about it? i had gone into but still cant find exactly what I need. Please help.... thanks

How to pass Listview contents to a crystal report for printing purposes using VB net..?
i got 1 listview which shows the results of some queries. Now my problem is how can i pass those data in my listview to the crystal report?

Thanks for all who tried to answer my query... anyway I solved it already... thanks again. hope you guys will continue to help those individuals out there needing your brilliant ideas.
;-) God bless all....

Here I reprogram it

 Private Sub ok_Click(sender As Object, e As EventArgs) Handles ok.Click
            Dim conn As New SqlConnection
            If TextBox1.Text = "" Or TextBox2.Text = "" Then
                MessageBox.Show("Please fill in all fields.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Else
                 conn.ConnectionString = "Data Source=DOLE-PC\SQLEXPRESS;Initial Catalog=db_dole;Integrated Security=True;"
                Try
                    Dim sql As String = "SELECT UName, Password, Usertype  FROM [db_dole].[dbo].[tbl_user] WHERE UName='" & TextBox1.Text & "' AND Password='" & TextBox2.Text & "'"
                    Dim cmd As New SqlCommand(sql, conn)

                    cmd.Connection = conn
                    conn.Open()

                    Dim dr As SqlDataReader = cmd.ExecuteReader

                    If dr.Read = True Then
                        sql = "SELECT Usertype FROM [db_dole].[dbo].[tbl_user] WHERE Usertype = 'Admin'"
                        Me.Hide()
                        MessageBox.Show("      W E L C O M E !")
                        mainform.Show()

                        If sql = "SELECT Usertype FROM [db_dole].[dbo].[tbl_user] WHERE Usertype = 'Normal'" Then
                            Me.Hide()
                            MessageBox.Show("      W E L C O M E !")
                            viewform.edit.Visible = False
                            viewform.Summary.Visible = False
                            viewform.NewRec.Visible = False
                            viewform.RFresh.Visible = False
                            viewform.Show()
                        End If
                    Else
                        MessageBox.Show("Incorrect Username or Password.", "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    End If
                Catch ex As Exception
                    MessageBox.Show("Failed to connect to databse. System Error:" & ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End Try
                If conn.State <> ConnectionState.Closed Then
                    conn.Close()
                End If
            End If

        End Sub

this time it will log in using both users from admin and normal, but all where in mainform. i want normal users can access only Viewform...

I need help about this, I've been working for this a quiet while...
I want to log-in using one login form for both admin and normal user but after log in, some of its form and/or buttons in the form should not be available for normal users.
here is my code upon login:

    Private Sub ok_Click(sender As Object, e As EventArgs) Handles ok.Click
        Dim conn As New SqlConnection
        If TextBox1.Text = "" Or TextBox2.Text = "" Then
            MessageBox.Show("Please fill in all fields.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Else
           conn.ConnectionString = "Data Source=DOLE-PC\SQLEXPRESS;Initial Catalog=db_dole;Integrated Security=True;"
            Try
                Dim sql As String = "SELECT UName, Password, Usertype  FROM [db_dole].[dbo].[tbl_user] WHERE UName='" & TextBox1.Text & "' AND Password='" & TextBox2.Text & "'"
                Dim cmd As New SqlCommand(sql, conn)

                cmd.Connection = conn
                conn.Open()

                Dim dr As SqlDataReader = cmd.ExecuteReader

                If dr.Read = True Then
                    If sql = "SELECT Usertype FROM [db_dole].[dbo].[tbl_user] WHERE Usertype = 'Admin'" Then
                        Me.Hide()
                        MessageBox.Show("      W E L C O M E !")
                        mainform.Show()

                    ElseIf dr.Read = True Then
                        sql = "SELECT Usertype FROM [db_dole].[dbo].[tbl_user] WHERE Usertype = 'Normal'"
                        Me.Hide()
                        MessageBox.Show("      W E L C O M E !")
                        viewform.Show()
                        viewform.edit.Visible = False
                        viewform.Summary.Visible = False
                        viewform.NewRec.Visible = False
                        viewform.RFresh.Visible = False
                    End If
                Else
                    MessageBox.Show("Incorrect Username or Password.", "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                End If
            Catch ex As Exception
            MessageBox.Show("Failed to connect to databse. System Error:" & ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
            If conn.State <> ConnectionState.Closed Then
                conn.Close()
            End If
        End If

    End Sub

here is a sample code:

Private Sub mainform_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        cmd.Connection = conn
        cmd.CommandText = "SELECT MAX(ColumnName)  FROM [db_Name].[dbo].[tbl_Name]"
        conn.Open()
        dr = cmd.ExecuteReader()
        Do While dr.Read()
        'max value showing on the textbox
            x.Text = x.Text & dr.GetValue(0) & vbTab
        Loop
        dr.Close()
        conn.Close()
    End Sub

btw, if this already answered post, kindly mark it as solved.

Rewriting in newer version, using code from old version and upgrade some feature is better than converting the old system to the latest.

Kindly check if the datatype length on your database can handle the number of characters you entered on your textboxes...

To avoid such error, go to your textbox properties and set the Max length of your textbox not exceeding the length set on your database.

hope this helps, i used to put this on my edit button BUT mine is listview and your is datagrid.....

Private Sub edit_Click(sender As Object, e As EventArgs) Handles edit.Click

        editForm.Show()
        If Not Listview1.SelectedItems.Count = 0 Then '// check if item is selected.
            With Listview1.SelectedItems.Item(0)
                editForm.x.Text = .Text '// column 1.
                editForm.TextBox1.Text = .SubItems(1).Text '// column 2.
                editForm.TextBox2.Text = .SubItems(2).Text '// column 3.
                editForm.TextBox3.Text = .SubItems(3).Text '// column 4.
                '// etc...
            End With
            'Form2.ShowDialog()
        End If

        Me.Hide()
    End Sub

I used this code in getting max number of records in my database hope you got an idea with this:

 Private Sub mainform_Load(sender As Object, e As EventArgs) Handles MyBase.Load

   cmd.Connection = conn
            cmd.CommandText = "SELECT MAX(ColumnName)  FROM [databaseName].[dbo].[tableName]"
            conn.Open()
            dr = cmd.ExecuteReader()
            Do While dr.Read()
                x.Text = x.Text & dr.GetValue(0) & vbTab
            Loop
            dr.Close()
            conn.Close()

End sub

Save button codes:

 Private Sub save_Click(sender As Object, e As EventArgs) Handles save.Click
        cmd.Connection = conn
        cmd.CommandText = "INSERT INTO [databasename].[dbo].[tableName] VALUES ('" & TextBox1.Text & "', '" & TextBox2.Text & "', '" & TextBox3.Text & "', '" & TextBox4.Text & "', '" & TextBox5.Text & "', '" & TextBox6.Text & "', '" & TextBox7.Text & "', '" & TextBox8.Text & "', '" & TextBox9.Text & "', '" & TextBox10.Text & "')"

        Try
            If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox4.Text = "" Or TextBox5.Text = "" Or DateTimePicker2.Text = "" Or TextBox6.Text = "" Or TextBox7.Text = "" Or DateTimePicker3.Text = "" Or DateTimePicker4.Text = "" Or y.Text = "" Or TextBox8.Text = "" Or TextBox9.Text = "" Or TextBox10.Text = "" Then
                MessageBox.Show("All fields Are Required", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Else
                conn.Open() 
                cmd.ExecuteNonQuery()
                MsgBox("Record Successfully Added")
            End If
        Finally
            conn.Close()
        End Try

        TextBox1.Clear()
        TextBox2.Clear()
        TextBox3.Clear()
        TextBox4.Clear()
        TextBox5.Clear()
        TextBox6.Clear()
        TextBox7.Clear()
        TextBox8.Clear()
        TextBox9.Clear()
        TextBox10.Clear()

    End Sub

textboxName.clear() will clear your data typed on textbox

Hi, we got same problem but then found no exact answer and so I switched to listview instead of datagridview. I will just show you how I programmed my edit button for my listview data after clicking specific data to be edited, and show it on my textboxes in other form.
Just hoping you will get some idea though...

Private Sub edit_Click(sender As Object, e As EventArgs) Handles edit.Click
        editForm.Show()
        If Not Listview1.SelectedItems.Count = 0 Then
            With Listview1.SelectedItems.Item(0)
                editForm.x.Text = .Text
                editForm.TextBox1.Text = .SubItems(1).Text
                editForm.TextBox2.Text = .SubItems(2).Text
                editForm.TextBox3.Text = .SubItems(3).Text
                editForm.TextBox4.Text = .SubItems(4).Text
                editForm.TextBox5.Text = .SubItems(5).Text
                editForm.DateTimePicker2.Text = .SubItems(6).Text
                editForm.TextBox6.Text = .SubItems(7).Text
                editForm.TextBox7.Text = .SubItems(8).Text
                editForm.DateTimePicker3.Text = .SubItems(9).Text
                editForm.DateTimePicker4.Text = .SubItems(10).Text
                editForm.y.Text = .SubItems(11).Text
                editForm.TextBox8.Text = .SubItems(12).Text
                editForm.TextBox9.Text = .SubItems(13).Text
                editForm.TextBox10.Text = .SubItems(14).Text
            End With
        End If
        Me.Hide()
    End Sub

Hi nosfa, are you trying to view your data in a listview table or in textboxes?
You may use queries attached on your searchbox like:

Dim sql = "SELECT UName,Password FROM [databaseName].[dbo].[tableName] WHERE UName = '" & TextBox1.Text & "' AND Password = '" & TextBox2.Text & "'"