By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

adding row numbers to datagrid

jamesd0142
100+
P: 469
Hi again!

Please see image...

I have retrieved this information from my database, i now want to add a row number to each row that is added...

any ideas?

Cheers
Sep 19 '07 #1
Share this Question
Share on Google+
3 Replies


hariharanmca
100+
P: 1,977
You have to do it in insert query or set a autonumber in database table.
Sep 19 '07 #2

P: 60
Hi again!

Please see image...

I have retrieved this information from my database, i now want to add a row number to each row that is added...

any ideas?

Cheers
hi!!
can u plz tell me how you have retrieved the entries from the database in a datagrid by coding

TIA
regards
vishwas
Sep 19 '07 #3

jamesd0142
100+
P: 469
at the top of the form below the public class

'connect to database
Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=FAQs.mdb"
Dim selectCommand As String

'create datasets
Dim dataSetView As New DataSet
Dim dataSetQuestion As New DataSet
Dim dataSetAnswer As New DataSet


Dim dataAdapter As New OleDb.OleDbDataAdapter(selectCommand, connectionString)
Dim commandBuilder As New OleDb.OleDbCommandBuilder(dataAdapter)


Inside a button or on frm load put:

dgvAnswer.DataSource = ""
dataSetAnswer.Clear()
selectCommand = "SELECT * FROM tblAnswer Order By Answer_Id"
dataAdapter.SelectCommand.CommandText = selectCommand
dataAdapter.Fill(dataSetAnswer, "AnswerView")
dgvAnswer.DataSource = dataSetAnswer.Tables("AnswerView")

DONT FORGET TO PUT YOUR DATABASE IN YOUR PROJECT FOLDER!
I put mine in bid\debug although i have been told this is bad practice.
Sep 19 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.