In my code I have a DataGridView object. I use it to know the row number when I browse the table.
I actually don't need this DataGridView object! I need to know the row number operation straight from the table located inside my SQL.
How can I do that?
Here is part of the code that utilize the DATAGridView (RaceDGView) and I want to change it accordingly
private void CellEditMethod() { int a = RaceDGView.Rows.Count; DataGridViewRow rowToSelect = RaceDGView.Rows[a - 1]; rowToSelect.Selected = true; rowToSelect.Cells[RaceDGView.SelectedCells[0].RowIndex].Selected = true; RaceDGView.CurrentCell = rowToSelect.Cells[RaceDGView.SelectedCells[0].RowIndex]; AddRowPositionLbl.Text = "Added row number is: " + Convert.ToString(RaceDGView.SelectedCells[0].RowIndex+1); RaceDGView.BeginEdit(true); }
PLZ HLP.
LiorPosted Nov 5, 2010, 12:58 PM
I got the solution myself.
to know on what row I am at the table in the SQL server all I need to type is:
BindingSource.Position;
And thats all!!!!
Thanks all whom tried to help (:
theLizardPosted Oct 30, 2010, 6:21 PM
Say you have a combo box with data from an sql table, if you load the combo box manually you can create a dynamic array and add the associated row id to the array so that when you want to access the record of the combo box item it is as easy as "SELECT * FROM table WHERE rowid = " + rowids[combobox->selectedindex];
In my case I have written components and component agents that do this by design and as the controls are being loaded from the database their row id is added to vector and properties of the control access the vector to return the record id like this int rowid = combobox->RecordId(); in this case it returns the id of the selected record.
Suthish NairPosted Oct 30, 2010, 8:20 AM
The best i can help you, refer this article about using DataGraidView
The rest is upon you, how to learn, implement and achieve.
Sam HobbsPosted Oct 30, 2010, 8:06 AM
LiorPosted Oct 30, 2010, 7:07 AM
Nair - I can use the primary key but don't know how
Sam HobbsPosted Oct 30, 2010, 6:37 AM
In How To Ask Questions The Smart Way it says that before you ask, try to find the answer, including reading the manual. It also says:
And it says much, much more that you need to read. Note that that page has been developed with the assistance of many people.
A shorter version of the above is in How To Ask Good Questions, which says:
Microsoft has written their version; see How to ask a question. You need to read that too. It also says to search the documentation, the internet, FAQs and previous answers in forums before asking a question.
Suthish NairPosted Oct 30, 2010, 6:31 AM
LiorPosted Oct 30, 2010, 6:25 AM
I actually don't need this DataGridView object! I need to know the row number operation straight from the table located inside my SQL so I could INSERT, UPDATE and DELETE rows.
How can I do that?
theLizardPosted Oct 30, 2010, 4:20 AM
LiorPosted Oct 30, 2010, 3:31 AM
No one does the work of the other!
If you think that you are being exploited so do not help-no one is forcing you!
I need help in coding and I do help others that need help in areas that I'm strong at. Not feeling exploited but helpfull that is why FORUMS exists - to help others helping themselves.
I'm a newbe at C# and SQL I don't know to program but I'm learning, by myself, and this and other forums are the best place to learn!
There are good people on the way that have the skill and patience to help and they do help!
So thanks to you but no thanks if you think that I'm an exploiter - I'M NOT!!!!
Sam HobbsPosted Oct 30, 2010, 3:03 AM
LiorPosted Oct 30, 2010, 2:32 AM
But if someone knows the solution for my problem why not simply ask?
Sam HobbsPosted Oct 30, 2010, 2:14 AM
LiorPosted Oct 30, 2010, 1:57 AM
I do use the MSDN forum. but I've come to conclusion that C# Corner forum is a very PRO forum so why not be a member too!?
About the search engine, well, here you can see the work of a good code plus a greate PR!!! and the outcome is obvious!
Like microsoft a nice code plus proffesional PR and marketing and you have an empire :)
And for my problem- I need a complete code sample if you please.
I do search a solution in all my available sources but for now got non!!! ):
Thanks
Sam HobbsPosted Oct 30, 2010, 12:45 AM
I think I distracted the discussion away from the most important point; that developers need to use MSDN more.
Suthish NairPosted Oct 30, 2010, 12:00 AM
I just typed the name becoz most people nowdays directly use this to find answers.
Sam HobbsPosted Oct 29, 2010, 8:16 PM
http://social.msdn.microsoft.com/Search/en-US?query=SqlCommand&ac=3
If answers are not found in the MSDN then it is useful to search this web site; then if an answer is still not found, search the entire internet using a search engine such as Google. Note that Google was not the first search engine and it is not the only one.
I think Google has paid the most money to get people to talk about them, but I sure have never gotten any of that.
Suthish NairPosted Oct 29, 2010, 4:58 PM
LiorPosted Oct 29, 2010, 3:08 PM
Nair - is the SQL code you wrote needs to be in the Sqlcommand? and the rest of my code will stay the same????
What "ROW_NUMBER()" relates to?
Suthish NairPosted Oct 29, 2010, 6:49 AM
please be specify about your post..
LiorPosted Oct 29, 2010, 5:34 AM
The end resault is that this code counts all the rows of my table and doesn't show the specific row that I'm standing on.
Lets say that I'm on row 5 and when I click my lable I want to see the number 5 and not the number of all the rows
private void SqlIdNumLbl_Click(object sender, EventArgs e)
{
//SqlIdNumLbl.Text = Convert.ToString(RaceDS.Tables[0].Rows.Count);
SqlCommand RowIdCmd = new SqlCommand("select count('ID') from RaceTbl", WorldConn);
WorldConn.Open();
{
SqlDataReader RowIdDrd = RowIdCmd.ExecuteReader();
while (RowIdDrd.Read())
{
SqlIdNumLbl.Text = Convert.ToString(RowIdDrd.GetInt32(0));
}
}
WorldConn.Close();
}
Hope that this make my problem more clear.
Sam HobbsPosted Oct 29, 2010, 4:51 AM
How are you reading the data into the DataGridView? If it were me, I would create a TableAdapter; that can be done in the Database Designer. If you do that then the only code you need to write is the code to create an instance of the TableAdapter and maybe one line to open it and then one line to get the count of the rows. You will need to spend some time learning but the time is well spent since you can re-use the knowledge many more times.
Manikavelu VelayuthamPosted Oct 29, 2010, 4:40 AM
SELECT ROW_NUMBER() OVER (ORDER BY EMPID ASC) AS ROWID, * FROM EMPLOYEE
LiorPosted Oct 29, 2010, 4:35 AM
I need to know on what row I am so I could edit or update it.
How can I do that? need a simple code sample.
Sam HobbsPosted Oct 28, 2010, 3:05 PM