How to update row in database through gridview in windows forms application
-
Saturday, September 22, 2012 10:54 AM
Hi ,
I am having a textbox ,two buttons(button1,button2) and a gridview in a form.
when I enter one field value in textbox and click the button1, gridview will display the record of that particular field.
when I update cells of gridview and click button2 it should update and display the Updated record.
I have been searching for this but dint found any thing related to windowsforms application.
Please help me!!
All Replies
-
Saturday, September 22, 2012 12:41 PM
Try to write exact your question. Windows Forms don't have a gridview
It has a datagrid and a DataGridView
Success
Cor -
Saturday, September 22, 2012 12:56 PM
-
Saturday, September 22, 2012 1:03 PM
Hi priya,
Exactly, also agreed with Mr. Cor,
see below said for certain operations inside DataGridView
http://www.dotnetperls.com/datagridview-vbnet
http://csharpdotnetfreak.blogspot.com/2009/07/display-total-in-gridview-footer.html
http://www.youtube.com/watch?v=AUWGmCCHT6w
Pl. Mark/Proposed as Answer if found your solution Vote as Helpful if related to your topic. Always Motivate others by performing this Action.
-
Monday, September 24, 2012 5:24 AMModerator
Hi Priya21,
Welcome to the MSDN forum.
If you are using WinForm application, please check following samples:
Example application data with SQLserver 2008 Express from Carmelo:
http://code.msdn.microsoft.com/Esempio-applicazione-dati-494c129a
Execute SQL statements stored in MS-Access in a VB.NET project sample from Kevininstructor:
http://code.msdn.microsoft.com/Execute-SQL-statements-aa3015b5
LINQ - Databinding using Windows Forms sample from Migrated:
http://code.msdn.microsoft.com/LINQ-Databinding-using-52d261d1
Hope this helps.
Mark Liu-lxf [MSFT]
MSDN Community Support | Feedback to us
- Proposed As Answer by ArifMustafa Monday, September 24, 2012 8:44 AM
-
Monday, September 24, 2012 5:42 AM
Priya,
any status of your issue?
Pl. Mark/Proposed as Answer if found your solution Vote as Helpful if related to your topic. Always Motivate others by performing this Action.
-
Monday, September 24, 2012 5:54 AM
Thanks for your responses!!!
I am using CommandBuilder for updating the cells of DataGridView. Here is my code :
Private Sub BtnRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If TextBox1.Text = "" Then MsgBox("Enter Individual Reference") Else _objCmd = New SqlCommand("select * from Agent where IndRef='" + TextBox1.Text + "'", _objCon) _objDa = New SqlDataAdapter(_objCmd) _objDs = New DataSet() _objDa.Fill(_objDs,"Agent") DataGridView1.DataSource = _objDs.Tables(0) DataGridView1.DataMember = "" End If End Sub Private Sub BtnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim i As Integer _objCmbldr = New SqlCommandBuilder(_objDa) Try i=_objDa.Update(_objDs) MsgBox("row is updated ") Catch ex As Exception MsgBox(ex.Message) End Try End SubIs there any possibility of placing both conditions ie.,displaying and updating in one button.
Please Help!!
- Marked As Answer by priya21 Monday, September 24, 2012 9:23 AM
-
Monday, September 24, 2012 6:35 AMModerator
Hi Priya21,
>>Is there any possibility of placing both conditions ie.,displaying and updating in one button.
Whether it will be possible depends upon whether you can distinguish the situation well.
For example, search all the record and search one specific record can be combained into “search” button. You can judge it by whether the search textbox contains the data.
I will suggest you to separate Displaying and updating into different buttons.
If you insist to use them in one button, here is a solution. You can check whether the dateset has been changed by using DataSet.HasChanges Method. If yes, accept the changes and use the update method. if not, using the display method.
Hope this helps.
Mark Liu-lxf [MSFT]
MSDN Community Support | Feedback to us
- Marked As Answer by priya21 Monday, September 24, 2012 9:23 AM
-
Monday, September 24, 2012 6:43 AM
-
Monday, September 24, 2012 7:48 AM
Thanks for the support!!
>>I will suggest you to separate Displaying and updating into different buttons.
I am using the same code according to what you have suggested.
- Edited by priya21 Monday, September 24, 2012 7:49 AM
-
Monday, September 24, 2012 8:39 AM
if you have found a solution, mark as answered,
pl. be updated!
Pl. Mark/Proposed as Answer if found your solution Vote as Helpful if related to your topic. Always Motivate others by performing this Action.
- Edited by ArifMustafa Monday, September 24, 2012 8:44 AM

