Click here to Skip to main content
16,007,610 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: How to update data by using datagird and textbox ? [modified] Pin
bircut5-Feb-07 2:10
bircut5-Feb-07 2:10 
GeneralRe: How to update data by using datagird and textbox ? Pin
Johan Hakkesteegt5-Feb-07 2:37
Johan Hakkesteegt5-Feb-07 2:37 
GeneralRe: How to update data by using datagird and textbox ? Pin
bircut5-Feb-07 2:47
bircut5-Feb-07 2:47 
GeneralRe: How to update data by using datagird and textbox ? Pin
Johan Hakkesteegt5-Feb-07 3:49
Johan Hakkesteegt5-Feb-07 3:49 
GeneralRe: How to update data by using datagird and textbox ? Pin
bircut5-Feb-07 4:19
bircut5-Feb-07 4:19 
GeneralRe: How to update data by using datagird and textbox ? Pin
Johan Hakkesteegt5-Feb-07 19:57
Johan Hakkesteegt5-Feb-07 19:57 
GeneralRe: How to update data by using datagird and textbox ? Pin
bircut5-Feb-07 20:27
bircut5-Feb-07 20:27 
GeneralRe: How to update data by using datagird and textbox ? Pin
Johan Hakkesteegt5-Feb-07 22:30
Johan Hakkesteegt5-Feb-07 22:30 
The problem is that the IsDBNull check can not access rows where the RowState is Deleted (so we tried to call AcceptChanges first, but your update statement needs to know the RowState of each datarow to work, and AcceptChanges sets all RowStates to Unchanged. That's why the code didn't throw any errors, but also didn't update anything, because table.GetChanges() didn't find any changes anymore.

However, if the row was deleted than we don't have to add the ClassID anyway. So let's try the following:

<br />
Private Sub ButtonUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonUpdate.Click<br />
dataConnection.Open()<br />
Dim temp As DataTable<br />
Try<br />
Dim r As DataRow<br />
For Each r In table.Rows<br />
If r.RowState <> DataRowState.Deleted Then<br />
If IsDBNull(r.Item("classID")) = True Then r.Item("classID") = TextboxClassID.Text<br />
End If<br />
Next<br />
temp = table.GetChanges() 'table is a dataTable which is used for datagrid source<br />
If Not temp Is Nothing Then dataAdapter.Update(temp)<br />
table.AcceptChanges() 'this may not be necessary<br />
Catch ex As Exception<br />
table.RejectChanges()<br />
dataConnection.Close()<br />
MsgBox(ex.ToString)<br />
End Try<br />
End If<br />
dataConnection.Close()<br />
End Sub<br />


Johan


My advice is free, and you may get what you paid for.

GeneralRe: How to update data by using datagird and textbox ? Pin
bircut6-Feb-07 4:59
bircut6-Feb-07 4:59 
GeneralRe: How to update data by using datagird and textbox ? Pin
Johan Hakkesteegt6-Feb-07 21:57
Johan Hakkesteegt6-Feb-07 21:57 
GeneralRe: How to update data by using datagird and textbox ? Pin
bircut6-Feb-07 22:50
bircut6-Feb-07 22:50 
GeneralRe: How to update data by using datagird and textbox ? Pin
Johan Hakkesteegt6-Feb-07 22:56
Johan Hakkesteegt6-Feb-07 22:56 
GeneralRe: How to update data by using datagird and textbox ? Pin
bircut7-Feb-07 0:41
bircut7-Feb-07 0:41 
GeneralRe: How to update data by using datagird and textbox ? [modified] Pin
bircut13-Feb-07 21:51
bircut13-Feb-07 21:51 
GeneralRe: How to update data by using datagird and textbox ? Pin
Johan Hakkesteegt14-Feb-07 22:30
Johan Hakkesteegt14-Feb-07 22:30 
GeneralRe: How to update data by using datagird and textbox ? Pin
bircut14-Feb-07 23:07
bircut14-Feb-07 23:07 
QuestionPopulating a combo box with file names from a directory. Pin
Ron.Com4-Feb-07 12:35
Ron.Com4-Feb-07 12:35 
AnswerRe: Populating a combo box with file names from a directory. Pin
Christian Graus4-Feb-07 12:37
protectorChristian Graus4-Feb-07 12:37 
QuestionDisplaying Forms Pin
jady844-Feb-07 12:10
jady844-Feb-07 12:10 
AnswerRe: Displaying Forms Pin
Christian Graus4-Feb-07 12:18
protectorChristian Graus4-Feb-07 12:18 
Questionenumerate db2 server in lan Pin
sal214-Feb-07 9:05
sal214-Feb-07 9:05 
QuestionAuto Launch @ windows start-up Pin
WestSideRailways4-Feb-07 8:00
WestSideRailways4-Feb-07 8:00 
AnswerRe: Auto Launch @ windows start-up Pin
MatrixCoder4-Feb-07 8:13
MatrixCoder4-Feb-07 8:13 
AnswerRe: Auto Launch @ windows start-up Pin
A*****4-Feb-07 16:06
A*****4-Feb-07 16:06 
GeneralRe: Auto Launch @ windows start-up Pin
WestSideRailways4-Feb-07 20:30
WestSideRailways4-Feb-07 20:30 

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.