Hi,
My application is in VS2008 coded in Vb.net.I have a datagridview which is populated from Database.I have a save button on the same form that has DatagridView.
My requirement is i want that all the records that are populated in DatagridView should be saved in a certain table of the database when the user clicks save.
Im done with my save and Update code.What im not able to do is,im not able to increment the counter and move to the next row of datagridView when my For loop is executing after the click of Save button.
Below is my Code. -
For i As Integer = 0 To DGVStudRecord.RowCount - 1
-
My Code for Update and Save.
-
Next
-
Here what is happening is when save button is clicked my for Loop is executing and looping till RowCount-1.But i want that after completion of each loop my i should get to the next row in the datagirdView.I should be able to get the values of next row to pass it to my controls that are carrying update and delete operation.
The entire data in the datagridview will be saved in a certain table at the click of save button.
Please suggest.
3 10115
Try -
-
DGVStudRecord.Rows(i).Cells(0).Text
-
Below is my actual Code.
I want the cursor to move to next row and provide respective column values to my update query. -
For i As Integer = 0 To DGVStudRecord.RowCount - 1
-
-
DBConnect()
-
Dim strsql1 As String = ""
-
con = DBActions.DBConnect
-
strsql1 = "Select No from TableName where No='" & DGVStudRecord.Item(0, DGVStudRecord.CurrentCell.RowIndex).Value & "'"
-
cmd = New SqlCommand(strsql1, con)
-
dr = cmd.ExecuteReader
-
If dr.HasRows = True Then
-
-
dr.Close()
-
strsql = "Update TableName set No='" & DGVStudRecord.Item(1, DGVStudRecord.CurrentCell.RowIndex).Value & "'," & _
-
"Column1='" & DGVStudRecord.Item(2, DGVStudRecord.CurrentCell.RowIndex).Value & "'," & _
-
"Column2='" & DGVStudRecord.Item(3, DGVStudRecord.CurrentCell.RowIndex).Value & "'," & _
-
"Column3='" & DGVStudRecord.Item(4, DGVStudRecord.CurrentCell.RowIndex).Value & "'," & _
-
"Column4='" & DGVStudRecord.Item(6, DGVStudRecord.CurrentCell.RowIndex).Value & "'," & _
-
-
"where No='" & DGVStudRecord.Item(0, DGVStudRecord.CurrentCell.RowIndex).Value & "'"
-
cmd = New SqlCommand(strsql, con)
-
cmd.ExecuteNonQuery()
-
dr.Close()
-
End If
-
End If
-
Please dont look for code it may contain error as i have truncated it.Just tell me how can i get the new row values to give it to query parameter to update.
Thanks frnds for ur support.
i got the solution to my query.
i just needed to add i in place of DGVStudRecord.CurrentCell.RowIndex. -
DGVStudRecord.Item(0,i).Value
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Dan |
last post by:
I'd like to loop through selected datagrid rows and extract specified
columns from those rows. How would I do that?
Thanks...
Dan
|
by: Sascha Meyer |
last post by:
Hi there,
I've tried several ways to resolve this problem and also searched the
net but I'm still not satisfied with my different solutions:
how do I check for rows in a DataReader in a CompactFramework Appication
with SQL Server CE?
I tried something like
sqlSCom.CommandText = "SELECT somerows FROM sometable"
|
by: nekiv90 |
last post by:
Greetings,
How can 'rows read' from a DB2 CALL statement incur so many reads? I
would expect it to be zero.
Could someone enlighten me on this? Thanks!
Here is output from executing event monitor on STATEMENTS:
68) Statement Event ...
|
by: Philip Wagenaar |
last post by:
I have a dataset that I queried from an excel sheet. I want to loop through
the rows, then loop through the columns and write them to a file. But I got
stuck pretty quickly:
So far:
For Each dr As DataRow In Order.Tables(0).Rows
Next
|
by: JohnK |
last post by:
from what I read & tried, DataGridView was meant for Window Forms, not for
ASP/Web pages... correct?
While I can use it to display data, I can't seem to figure out how to edit
the cells... I'm not looking to put edit buttons on each row... I'll go back
to regular window forms before I create such an interface..
So is it true, in ASP.Net...
| |
by: jjmurali |
last post by:
hi guys
i have one problem with datagridview.. i m displaying data in datagridview in c# application. i added one checkbox column to datagridview ..as well as i have one button(Select All), whenever i click the button all check boxes checked in checkboxes column. i have another button(Remove) whenever i click the button remove the selected...
|
by: Hetal |
last post by:
Hi there..
I am a VB6 developer so kinda trying to figure how to work with
VB.NET. I have a scenario where i have a DataSet bound to a combo box,
and i would like to read a row from the DataSet based on the item
selected in the Combo Box.
For e.g.
I have a dataset that has 1 table containing 3 fields say ID, Name,
and Address.
|
by: obrienkev |
last post by:
Hi all,
I have used the below to display the cell content of the datagridview cell the user clicked on.
However, the MessageBox is displayed twice.
|
by: gm41970 |
last post by:
I have a datagridview in a .NET C# app that I have set to be read-only (grdXXXX.ReadOnly = true) since I do not want users to edit data that is already there. But I need to allow user to insert new row and add new info. I can add the row (using Columns.AddRange() but since the datagridview is set to read-only, cannot actually type the data into...
|
by: cday119 |
last post by:
Hi Everyone,
So I have a datagridview and it has a column called status. It has 3 values: New, Printed, and Shipped.
Now a user can select multiple rows and click "set to printed". I then do a foreach loop on datagridview.selectedrows and change the status to printed. Now the problem is that if the datagridview is sorted by status, when...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |