Click here to Skip to main content
15,895,740 members
Home / Discussions / Windows Forms
   

Windows Forms

 
GeneralRe: Simple question about button on windows forms Pin
Giorgi Dalakishvili11-Sep-07 0:05
mentorGiorgi Dalakishvili11-Sep-07 0:05 
AnswerRe: Simple question about button on windows forms Pin
Christian Graus11-Sep-07 0:03
protectorChristian Graus11-Sep-07 0:03 
GeneralRe: Simple question about button on windows forms Pin
Urs Enzler11-Sep-07 3:02
Urs Enzler11-Sep-07 3:02 
GeneralRe: Simple question about button on windows forms Pin
Giorgi Dalakishvili11-Sep-07 3:09
mentorGiorgi Dalakishvili11-Sep-07 3:09 
QuestionDatagrid ID value Automatic [modified] Pin
somagunasekaran10-Sep-07 3:29
somagunasekaran10-Sep-07 3:29 
QuestionHow to Delete the Datagrid Row Pin
somagunasekaran9-Sep-07 21:56
somagunasekaran9-Sep-07 21:56 
QuestionDataGrid control WinFroms Pin
somagunasekaran9-Sep-07 17:39
somagunasekaran9-Sep-07 17:39 
AnswerRe: DataGrid control WinFroms Pin
John_Adams30-Apr-08 22:45
John_Adams30-Apr-08 22:45 
Hi,

Below is the code snippet showing how we can insert, update and delete records using ADO.NET with DataGrid control.

-------------------------------------------------------------------------
BEGIN CODE

Private Const SELECT_STRING As String = _
"SELECT * FROM Contacts ORDER BY LastName, FirstName"
Private Const CONNECT_STRING As String = _
"Data Source=Bender\NETSDK;Initial " & _
"Catalog=Contacts;User Id=sa"

' The DataSet that holds the data.
Private m_DataSet As DataSet

' Load the data.
Private Sub Form1_Load(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
Dim data_adapter As SqlDataAdapter

' Create the SqlDataAdapter.
data_adapter = New SqlDataAdapter(SELECT_STRING, _
CONNECT_STRING)

' Map Table to Contacts.
data_adapter.TableMappings.Add("Table", "Contacts")

' Fill the DataSet.
m_DataSet = New DataSet()
data_adapter.Fill(m_DataSet)

' Bind the DataGrid control to the Contacts DataTable.
dgContacts.SetDataBinding(m_DataSet, "Contacts")
End Sub

Private Sub Form1_Closing(ByVal sender As Object, ByVal e _
As System.ComponentModel.CancelEventArgs) Handles _
MyBase.Closing

If m_DataSet.HasChanges() Then

Dim data_adapter As SqlDataAdapter
Dim command_builder As SqlCommandBuilder

' Create the DataAdapter.
data_adapter = New SqlDataAdapter(SELECT_STRING, _ CONNECT_STRING)

' Map Table to Contacts.
data_adapter.TableMappings.Add("Table", "Contacts")

' Make the CommandBuilder generate the
' insert, update, and delete commands.
command_builder = New SqlCommandBuilder(data_adapter)

' Uncomment this code to see the INSERT,
' UPDATE, and DELETE commands.
'Debug.WriteLine("*** INSERT ***")
'Debug.WriteLine(command_builder.GetInsertCommand.CommandText)
'Debug.WriteLine("*** UPDATE ***")
'Debug.WriteLine(command_builder.GetUpdateCommand.CommandText)
'Debug.WriteLine("*** DELETE ***")
'Debug.WriteLine(command_builder.GetDeleteCommand.CommandText)

' Save the changes.
data_adapter.Update(m_DataSet)
End If
End Sub

END CODE
-------------------------------------------------------------------------

You may make some more enhancement in the code. For example, you may check the DataSet's HasChanges method to see if there are any changes been made before you go to create a new SqlDataAdapter and SqlCommandBuilder. It may also be more efficient to save changes grouped by type: all inserts, all updates, all deletes. The basic program, however, is trivial and is perfectly adequate if the user won't make a huge number of changes.

Hope this helps Smile | :) .

Regards,
John Adams
ComponentOne LLC

QuestionHow to change a panel's controls from another form? Pin
DogMa3x7-Sep-07 11:59
DogMa3x7-Sep-07 11:59 
QuestionMultiple Forms Subscribing to the same event/data? Pin
basi00147-Sep-07 6:57
basi00147-Sep-07 6:57 
GeneralCrystal Reports ButtonTranslate Method Pin
Juan Pablo G.C.6-Sep-07 22:48
Juan Pablo G.C.6-Sep-07 22:48 
GeneralRe: Crystal Reports ButtonTranslate Method Pin
Chetan Patel7-Sep-07 2:44
Chetan Patel7-Sep-07 2:44 
QuestionError on file.copy Pin
samerh6-Sep-07 21:30
samerh6-Sep-07 21:30 
AnswerRe: Error on file.copy Pin
Chetan Patel7-Sep-07 2:41
Chetan Patel7-Sep-07 2:41 
AnswerRe: Error on file.copy Pin
Scott Dorman7-Sep-07 4:57
professionalScott Dorman7-Sep-07 4:57 
QuestionDropdown list event in Windows forms (.NET 2.0) Pin
Subrahmanyam K6-Sep-07 1:45
Subrahmanyam K6-Sep-07 1:45 
Questionundo Pin
ellllllllie5-Sep-07 4:38
ellllllllie5-Sep-07 4:38 
AnswerRe: undo Pin
Dave Kreskowiak5-Sep-07 5:23
mveDave Kreskowiak5-Sep-07 5:23 
AnswerRe: undo Pin
Pete O'Hanlon5-Sep-07 12:12
mvePete O'Hanlon5-Sep-07 12:12 
GeneralRe: undo Pin
Paul Conrad26-Sep-07 16:16
professionalPaul Conrad26-Sep-07 16:16 
QuestionWinForms Applications connected to databases best practices Pin
Marcosm644-Sep-07 15:24
Marcosm644-Sep-07 15:24 
AnswerRe: WinForms Applications connected to databases best practices Pin
Giorgi Dalakishvili4-Sep-07 20:50
mentorGiorgi Dalakishvili4-Sep-07 20:50 
GeneralRe: WinForms Applications connected to databases best practices Pin
Marcosm645-Sep-07 9:02
Marcosm645-Sep-07 9:02 
QuestionMore trouble with tool tips... Pin
chaiguy13374-Sep-07 15:08
chaiguy13374-Sep-07 15:08 
QuestionGet the folder path Pin
vimal_yet4-Sep-07 1:16
vimal_yet4-Sep-07 1:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.