Adding Ranking Column (just a column incrementing by 1 each row) to datagrid
-
Can someone tell me how to make a column in a datagrid that simply puts the number of the record in its field? ie: (Rnk Column) Rnk Name 1 aaa 2 bbb 3 ccc 4 ddd Thanks Cavall "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson
-
Can someone tell me how to make a column in a datagrid that simply puts the number of the record in its field? ie: (Rnk Column) Rnk Name 1 aaa 2 bbb 3 ccc 4 ddd Thanks Cavall "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson
Public Shared Function Rank() As DataTable Dim ds As DataSet = SqlHelper.ExecuteDatase(ConfigurationSettings.AppSettings(myProj.ConnectionString), "usp_GetRankedList") Dim dt As New DataTable() dt.Columns.Add("Rank") dt.Columns.Add("Name") Dim r As DataRow Dim workRow As DataRow Dim i As Integer = 1 For Each r In ds.Tables(0).Rows workRow = dt.NewRow workRow("Rank") = i workRow("Name") = r("Name") dt.Rows.Add(workRow) i += 1 Next Return dt End Function Watch for line break! Have fun!
-
Public Shared Function Rank() As DataTable Dim ds As DataSet = SqlHelper.ExecuteDatase(ConfigurationSettings.AppSettings(myProj.ConnectionString), "usp_GetRankedList") Dim dt As New DataTable() dt.Columns.Add("Rank") dt.Columns.Add("Name") Dim r As DataRow Dim workRow As DataRow Dim i As Integer = 1 For Each r In ds.Tables(0).Rows workRow = dt.NewRow workRow("Rank") = i workRow("Name") = r("Name") dt.Rows.Add(workRow) i += 1 Next Return dt End Function Watch for line break! Have fun!
thanks for the reply, but my main problem is this... i have another table in a dataset that I want to joing, say to that table you just created, link them on a field, and then pull the results from that join. ie. all the fields from the second table and the rank field on the first table.. the join would, for example, be on the "Name" field... Got any ideas? Thanks cavall "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson
-
thanks for the reply, but my main problem is this... i have another table in a dataset that I want to joing, say to that table you just created, link them on a field, and then pull the results from that join. ie. all the fields from the second table and the rank field on the first table.. the join would, for example, be on the "Name" field... Got any ideas? Thanks cavall "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson
If you are using a stored procedure, you should probably take care of any joining you want to do there. Just use the vbDataGrid for display. If you go this way I've found www.sqlteam/forums to be very helpful if you are unsure of how to put that stored procedure together. Good luck
-
If you are using a stored procedure, you should probably take care of any joining you want to do there. Just use the vbDataGrid for display. If you go this way I've found www.sqlteam/forums to be very helpful if you are unsure of how to put that stored procedure together. Good luck
is there a way around not using stored procedures? It is a lengthy process to get our DBA to create those procedures and so being able to do joins on the fly in vs.net would be awesome... do you know of a way to do this? thanks cav "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson
-
is there a way around not using stored procedures? It is a lengthy process to get our DBA to create those procedures and so being able to do joins on the fly in vs.net would be awesome... do you know of a way to do this? thanks cav "Nothing is at last sacred, but the integrity of your own mind." "What lies behind us and what lies before us are nothing compared to what lies within us." - Ralph Waldo Emerson
I'm sure there is a way around it, I'm not familiar with it though, it's not considered "best practice". www.msdn.com may help, or maybe you could post a topic based on that.