how to sql query

smokin

Member
Joined
Apr 22, 2006
Messages
12
Programming Experience
Beginner
Thanks John.

One last question I have and then I think i'll be set as thats now working.

I currently populate that datagrid just with the name column out of the table, however it has a id, name, location, date for the tournaments in the table.

My code is this currently for just pulling the name and displaying it in the datagrid;

Dim conn As New MySqlConnection
Dim myCommand As New MySqlCommand
Dim myAdapter As New MySqlDataAdapter
Dim myData As New DataTable
Dim SQL As String
SQL = "SELECT e.name FROM tournament e WHERE 1"


conn.ConnectionString = "server=serverdomain.co.nz;" _
&
"user id=username;" _
&
"password=password;" _
&
"database=tablename"


Try
conn.Open()
Try
myCommand.Connection = conn
myCommand.CommandText = SQL
myAdapter.SelectCommand = myCommand
myAdapter.Fill(myData)
dgvTournaments.DataSource = myData
Catch myerror As MySqlException
MsgBox(
"There was an error reading from the database: " & myerror.Message)
End Try
Catch myerror As MySqlException
MessageBox.Show(
"Error connecting to the database: " & myerror.Message)
Finally
If conn.State <> ConnectionState.Closed Then conn.Close()
End Try


I know how to alter the query so that it pulls the id, location etc etc. but how do i get it so that I can say pull a query for the id, name, location, date but only show in the datagrid the Name and Location, I dont want to display the ID but store the varible for the id?

Also the names of the columns are the table column names, so when i pull column name it calls the column name, how do i name the column when i display it rather than using the default name of the column?
 
I splitted this post out to a Sql forum question.
 
Back
Top