Solved

Rename Column of DataGridView

Posted on 2007-12-03
6
1,769 Views
Last Modified: 2013-11-26
I want to display a grid with the data from this sql query

SELECT * FROM invoices WHERE ddate >= curdate() - interval 180 day  AND equipment = 1 order by invoice_number desc

I think i have it working, however when i load the form in the program, I get an empty box.

I have attached the entire code

The columns i want are

invoice_number, ddate, company_name, and initials]

If possible, i would like the column names to be

Invoice Number, Date, Company Name and Initials

Just to make sure the connection works, i put a message box with the number of rows it found, and it returns the correct value.

I am just starting to learn vb.net so if the answer could explain as much as possible that would be a big help.


Imports MySql.Data.MySqlClient
Imports System.Data
 
 
 
Public Class frmLookupInvoice
 
    Private Sub frmLookupInvoice_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
        Dim conn As New MySqlConnection
        Dim myCommand As New MySqlCommand
        Dim BindingSource1 As New BindingSource
        Dim myAdapter As New MySql.Data.MySqlClient.MySqlDataAdapter
        Dim dt As New DataTable
        Dim dv As New DataView
        Dim SQL
 
        conn.ConnectionString = My.Settings.csInventory
 
        Try
            conn.Open()
            myCommand.Connection = conn
            SQL = "SELECT invoice_number, ddate, company_name, and initials FROM invoices WHERE ddate >= curdate() - interval 180 day  AND equipment = 1 order by invoice_number desc"
            myCommand.CommandText = SQL
            myAdapter.SelectCommand = myCommand
            myAdapter.Fill(dt)
            Dim numRows As Integer = dt.Rows.Count
 
            If (numRows) = 0 Then
                MessageBox.Show("No Invoices found")
            End If
 
            If (numRows) > 0 Then
 
                MessageBox.Show("Rows Found: " & dt.Rows.Count)
            End If
            conn.Close()
        Catch sqlerr As MySqlException
            MessageBox.Show(sqlerr.Message, "Error: " & sqlerr.Number)
 
            conn.Dispose()
        End Try
        'Dim invoice_number = dt.Rows(0)("access_level")
        myAdapter.GetFillParameters()
        'dt.Columns.Add(New DataColumn("Invoice Number", GetType(System.String), "invoice_number"))
        DataGridView1.DataSource = dv
 
 
 
 
 
 
 
 
    End Sub
 
    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
 
    End Sub
End Class

Open in new window

0
Comment
Question by:revo1059
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 16

Expert Comment

by:SQL_SERVER_DBA
ID: 20398274
You can do this in the GridView's RowDataBound or RowCreated event. You just have to filter the RowType to make sure it's a Header.

The sample below is in C# if you don't mind.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

    if(e.Row.RowType == DataControlRowType.Header)

    {

        e.Row.Cells[0] = "Column Name";


    }


}

http://forums.asp.net/p/1106969/1696341.aspx
0
 
LVL 1

Author Comment

by:revo1059
ID: 20398365
I am using visual basic and connecting to mysql database.  Can you show me in visual basic?
0
 
LVL 16

Expert Comment

by:SQL_SERVER_DBA
ID: 20398422
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 10

Accepted Solution

by:
vadim63 earned 500 total points
ID: 20399157
Why don't you change the query itself:

SQL = "SELECT invoice_number as [Invoice Number], ddate as [Date], company_name as [Company Name], and initials as [Initials] FROM invoices WHERE ddate >= curdate() - interval 180 day  AND equipment = 1 order by invoice_number desc"
0
 
LVL 1

Author Comment

by:revo1059
ID: 20400474
I didn't know  you could do that


You don't have to answer this, I can make another question but, How do you make a simple repeating region.  See, I am used to web design using dreamweaver.  If i wanted a table full of data, I would just drag the items from the bindings panel, and slap on a repeating region, and it would display all the records.  I am trying to find a way of doing that here, and I just can't seem to figure out how
0
 
LVL 10

Expert Comment

by:vadim63
ID: 20400991
Actually, it's very simple with VB2005. Go to the "Data Sources" tab, click "add new data source" and follow the wizard questions. There's a list of walkthroughs:
http://msdn2.microsoft.com/en-us/ms171923(VS.80).aspx
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question