Click here to Skip to main content
15,926,596 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: After sorting in a DataGridView the Row.EndEdit causes row change Pin
Marcus J. Smith4-Jun-07 9:17
professionalMarcus J. Smith4-Jun-07 9:17 
GeneralRe: After sorting in a DataGridView the Row.EndEdit causes row change Pin
Dave Kreskowiak4-Jun-07 10:24
mveDave Kreskowiak4-Jun-07 10:24 
GeneralRe: After sorting in a DataGridView the Row.EndEdit causes row change Pin
Marcus J. Smith4-Jun-07 10:56
professionalMarcus J. Smith4-Jun-07 10:56 
GeneralRe: After sorting in a DataGridView the Row.EndEdit causes row change Pin
Dave Kreskowiak4-Jun-07 13:38
mveDave Kreskowiak4-Jun-07 13:38 
GeneralRe: After sorting in a DataGridView the Row.EndEdit causes row change Pin
Marcus J. Smith5-Jun-07 2:26
professionalMarcus J. Smith5-Jun-07 2:26 
GeneralRe: After sorting in a DataGridView the Row.EndEdit causes row change Pin
Marcus J. Smith5-Jun-07 8:09
professionalMarcus J. Smith5-Jun-07 8:09 
GeneralRe: After sorting in a DataGridView the Row.EndEdit causes row change Pin
Dave Kreskowiak6-Jun-07 16:36
mveDave Kreskowiak6-Jun-07 16:36 
QuestionDataSet writing errors with code Pin
Quecumber2564-Jun-07 2:26
Quecumber2564-Jun-07 2:26 
Can someone tell me the difference between these similar dataset writing routines?

The data writing subroutine:
Private Sub New_Bindings(ByVal intOrdinal As Integer, _
ByVal strCode As String, _
ByVal strName As String)

drCurrent = MyDataSet.Tables("tblBindings").NewRow()
drCurrent!Ordinal = intOrdinal
drCurrent!BindingCode = strCode
drCurrent!BindingName = strName
MyDataSet.Tables("tblBindings").Rows.Add(drCurrent)
Call Show_Changes("Sub New_Bindings", MyDataSet)
End Sub

After each row is written into the dataset I have another subroutine that prints out the results called Show_Changes.

Case one – The data is placed directly into the subroutine call.

I’m writing 5 rows to the dataset like this:
Call New_Bindings(1, "TST1", "Record 1")
Call New_Bindings(2, "TST2", "Record 2")
Call New_Bindings(3, "TST3", "Record 3")
Call New_Bindings(4, "TST4", "Record 4")
Call New_Bindings(5, "TST5", "Record 5")

Output screen results after each row addition:
Sub - Sub New_Bindings
TableName: tblBindings
1 TST1 1 Record 1
Sub - Sub New_Bindings
TableName: tblBindings
1 TST1 1 Record 1
2 TST2 2 Record 2
Sub - Sub New_Bindings
TableName: tblBindings
1 TST1 1 Record 1
2 TST2 2 Record 2
3 TST3 3 Record 3
Sub - Sub New_Bindings
TableName: tblBindings
1 TST1 1 Record 1
2 TST2 2 Record 2
3 TST3 3 Record 3
4 TST4 4 Record 4
Sub - Sub New_Bindings
TableName: tblBindings
1 TST1 1 Record 1
2 TST2 2 Record 2
3 TST3 3 Record 3
4 TST4 4 Record 4
5 TST5 5 Record 5

This works just fine. All the records have been written to the dataset and I can use the BindingNavigator control to go from record to record.

Case 2 – The data is placed into the subroutine via variables.
Call New_Bindings(CInt(txtOrdinal.Text), txtBindingCode.Text, txtBindingName.Text)

Output screen after the same five rows are added.
Sub - Sub New_Bindings
TableName: tblBindings
1 TST1 1 Record 1
Sub - Sub New_Bindings
TableName: tblBindings
1 TST2 2
2 TST2 2 Record 2
Sub - Sub New_Bindings
TableName: tblBindings
1 TST3 3
2 TST2 2 Record 2
3 TST3 3 Record 3
Sub - Sub New_Bindings
TableName: tblBindings
1 TST4 4
2 TST2 2 Record 2
3 TST3 3 Record 3
4 TST4 4 Record 4
Sub - Sub New_Bindings
TableName: tblBindings
1 TST5 5
2 TST2 2 Record 2
3 TST3 3 Record 3
4 TST4 4 Record 4
5 TST5 5 Record 5

As you can see the dataset is not the same. The method of data entry is the same except that case 2 uses variables instead of literals. Obviously .NET handles these two similar data entry methods differently, but I haven’t a clue as to how or why this occurs.

Here is the entire code for this one form:
Option Explicit On
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlTypes
Imports System.Data.SqlDbType
Imports System.Data.SqlClient

Public Class frmBindings
Dim Msg As String
Dim strSQL As String
'Declare the SQLDataAdapter and DataSet objects
Dim daBindings As New SqlDataAdapter()
Dim objCommandBuilder As New SqlCommandBuilder(daBindings)
Dim MyDataSet As New DataSet()
Dim changesDataSet As DataSet
Dim drCurrent As DataRow

Private Function Is_Filled_Out() As Boolean
Dim b1 As Boolean, b2 As Boolean, b3 As Boolean
If (txtOrdinal.Text = Nothing) Then
txtOrdinal.BackColor = Color.Yellow
b1 = False
Else
txtOrdinal.BackColor = Color.White
b1 = True
End If
If (txtBindingCode.Text = Nothing) Then
txtBindingCode.BackColor = Color.Yellow
b2 = False
Else
txtBindingCode.BackColor = Color.White
b2 = True
End If
If (txtBindingName.Text = Nothing) Then
txtBindingName.BackColor = Color.Yellow
b3 = False
Else
txtBindingName.BackColor = Color.White
b3 = True
End If
Is_Filled_Out = b1 And b2 And b3
End Function

Private Sub Clear_Form()
txtBindingID.Text = Nothing
txtBindingCode.Text = Nothing
txtBindingName.Text = Nothing
txtOrdinal.Text = Nothing
txtOrdinal.Focus()
End Sub

Private Sub Load_DataSet()
'Connect to the SQL Server database
Dim cn As SqlConnection = New SqlConnection(My.Settings. _
PrintsByMe_DevConnectionString)
cn.Open()
'Retrieve the data using a SQL statement
strSQL = "SELECT * FROM [tblBindings];"
Dim cd As New SqlCommand(strSQL, cn)
'Set the database connection for MySqlDataAdapter
daBindings.SelectCommand = cd
'Fill the DataSet and DataSet Schema
daBindings.MissingSchemaAction = MissingSchemaAction.AddWithKey
daBindings.FillSchema(MyDataSet, SchemaType.Source, "tblBindings")
daBindings.Fill(MyDataSet, "tblBindings")
'Close database connection
cn.Close()
MyDataSet.Tables(0).Columns("BindingID").AutoIncrement = True
MyDataSet.Tables(0).Columns("BindingID").AutoIncrementSeed = 1
MyDataSet.Tables(0).Columns("BindingID").AutoIncrementStep = 1
'Set the BindingNavigator's DataSource to the DataSet we created.
bsBindings.DataSource = MyDataSet
'Set the BindingSource Datamember to the table we are using.
bsBindings.DataMember = MyDataSet.Tables(0).TableName()
'Bind form control txtBindingID to the BindingID field
txtBindingID.DataBindings.Add("Text", bsBindings, "BindingID")
'Bind form control txtOrdinal to the Ordinal field
txtOrdinal.DataBindings.Add("Text", bsBindings, "Ordinal")
'Bind form control txtBindingCode to the BindingCode field
txtBindingCode.DataBindings.Add("Text", bsBindings, "BindingCode")
'Bind form control txtBindingName to the BindingName Field
txtBindingName.DataBindings.Add("Text", bsBindings, "BindingName")
End Sub

Private Sub New_Bindings(ByVal intOrdinal As Integer, _
ByVal strCode As String, _
ByVal strName As String)


drCurrent = MyDataSet.Tables("tblBindings").NewRow()
drCurrent!Ordinal = intOrdinal
drCurrent!BindingCode = strCode
drCurrent!BindingName = strName
MyDataSet.Tables("tblBindings").Rows.Add(drCurrent)
Call Show_Changes("Sub New_Bindings", MyDataSet)
End Sub

Private Sub btnClose_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btnExit.Click
Me.Close()
End Sub

Private Sub frmBindings_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load

Call Load_DataSet()
naviBindings.BindingSource = bsBindings
End Sub

Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles BindingNavigatorAddNewItem.Click

Call New_Bindings(CInt(txtOrdinal.Text), txtBindingCode.Text, txtBindingName.Text)
Call Clear_Form()
End Sub


Private Sub BindingNavigatorUpdateDB_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles BindingNavigatorUpdateDB.Click
Dim intModified As Integer
Dim intAdded As Integer
Dim intRes As Integer
If MyDataSet.HasChanges(DataRowState.Modified Or DataRowState.Added) Then
changesDataSet = MyDataSet.GetChanges(DataRowState.Modified Or DataRowState.Added)
'Call Show_Changes(changesDataSet)
intModified = Modified_Records(changesDataSet)
intAdded = Added_Records(changesDataSet)
Msg = "You have modified " & CStr(intModified) & " records and " & _
"have added " & CStr(intAdded) & " records." & _
vbCRLF & "Do you wish to commit these changes to the database?"
intRes = MsgBox(Msg, MsgBoxStyle.Information + MsgBoxStyle.YesNo, "DataSet Changes")
If intRes = vbYes Then
'daBindings.Update(MyDataSet, "tblBindings")
Call Show_Changes("BindingNavagatorUpdateDB", changesDataSet)
Else
Msg = "Changes aborted." & vbCRLF & "The DataSet has NOT updated the database."
End If
End If
End Sub

Private Sub BindingNavigatorSaveNewItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles BindingNavigatorSaveNewItem.Click
If Is_Filled_Out() Then
Call New_Bindings(CInt(txtOrdinal.Text), txtBindingCode.Text, txtBindingName.Text)
Call Clear_Form()
Else
Msg = "Please fill in the highlighted box(es)."
MsgBox(Msg, MsgBoxStyle.Information + MsgBoxStyle.OkOnly)
End If
'txtOrdinal.Focus()
'Call New_Bindings(1, "TST1", "Record 1")
'Call New_Bindings(2, "TST2", "Record 2")
'Call New_Bindings(3, "TST3", "Record 3")
'Call New_Bindings(4, "TST4", "Record 4")
'Call New_Bindings(5, "TST5", "Record 5")
End Sub

End Class

Thanks,


Quecumber256
AnswerRe: DataSet writing errors with code Pin
Sathesh Sakthivel4-Jun-07 3:12
Sathesh Sakthivel4-Jun-07 3:12 
GeneralRe: DataSet writing errors with code Pin
Quecumber2564-Jun-07 4:53
Quecumber2564-Jun-07 4:53 
GeneralRe: DataSet writing errors with code Pin
Marcus J. Smith4-Jun-07 9:20
professionalMarcus J. Smith4-Jun-07 9:20 
GeneralRe: DataSet writing errors with code Pin
Quecumber2564-Jun-07 10:17
Quecumber2564-Jun-07 10:17 
Questionvb.net Pin
srinivassam4-Jun-07 2:01
srinivassam4-Jun-07 2:01 
AnswerRe: vb.net Pin
kubben4-Jun-07 2:26
kubben4-Jun-07 2:26 
AnswerRe: vb.net Pin
Christian Graus4-Jun-07 2:52
protectorChristian Graus4-Jun-07 2:52 
Questiona question about row-index Pin
vbbeg4-Jun-07 1:47
vbbeg4-Jun-07 1:47 
AnswerRe: a question about row-index Pin
Dave Kreskowiak4-Jun-07 4:06
mveDave Kreskowiak4-Jun-07 4:06 
GeneralRe: a question about row-index Pin
vbbeg4-Jun-07 4:56
vbbeg4-Jun-07 4:56 
GeneralRe: a question about row-index Pin
Dave Kreskowiak4-Jun-07 6:32
mveDave Kreskowiak4-Jun-07 6:32 
GeneralRe: a question about row-index Pin
vbbeg4-Jun-07 7:11
vbbeg4-Jun-07 7:11 
GeneralRe: a question about row-index Pin
Dave Kreskowiak4-Jun-07 8:09
mveDave Kreskowiak4-Jun-07 8:09 
GeneralRe: a question about row-index Pin
Dave Kreskowiak4-Jun-07 13:33
mveDave Kreskowiak4-Jun-07 13:33 
GeneralRe: a question about row-index Pin
vbbeg4-Jun-07 17:24
vbbeg4-Jun-07 17:24 
QuestionProblem in adding dll files Pin
Nanda16054-Jun-07 0:59
Nanda16054-Jun-07 0:59 
AnswerRe: Problem in adding dll files Pin
WhiteGirl234-Jun-07 2:07
WhiteGirl234-Jun-07 2:07 

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.