I am using VB 2008 with SQL 2008.
When I add a new record which is working flawlessly but along with that the code will modify the the previous record to the same which I just updated.
I have no idea why this is happening.
Below is the code which I am using to create a new record.
Below is teh code which I am using ti save any changes done to the dataset
i.e Add, Modify or delete.
Please let me know where I am going wrong.
Regards
Sudhir
When I add a new record which is working flawlessly but along with that the code will modify the the previous record to the same which I just updated.
I have no idea why this is happening.
Below is the code which I am using to create a new record.
VB.NET:
Private Sub AddBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddBtn.Click
flag = 0
SrTxt.Text = ""
TitTxt.Text = ""
MediaTxt.Text = ""
GenreTxt.Text = ""
DescTxt.Text = ""
CostTxt.Text = ""
LangTxt.Text = ""
RatingsTxt.Text = ""
StaringTxt.Text = ""
DiscTxt.Text = ""
StatusTxt.Text = ""
flag = 1
Dim len As Integer
dt = CollectionDataSet1.CD_DVDCollection
If dt.Rows.Count = 0 Then
SrlNo = 1
SrTxt.Text = SrlNo
Else
len = dt.Rows.Count - 1
dr = dt.Rows(len)
SrlNo = dr("Sl_No")
SrlNo = CInt(SrlNo) + 1
SrTxt.Text = SrlNo
SerialNo = SrlNo
End If
SrTxt.Enabled = False
TitTxt.Enabled = True
MediaTxt.Enabled = True
GenreTxt.Enabled = True
DescTxt.Enabled = True
CostTxt.Enabled = True
LangTxt.Enabled = True
RatingsTxt.Enabled = True
StaringTxt.Enabled = True
DiscTxt.Enabled = True
StatusTxt.Enabled = True
End Sub
Below is teh code which I am using ti save any changes done to the dataset
i.e Add, Modify or delete.
VB.NET:
Private Sub SaveBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveBtn.Click
SrChk:
If flag = 1 Then
If SerialNo = SrTxt.Text Then
dt = CollectionDataSet1.CD_DVDCollection
dr = dt.NewRow()
dr("Sl_No") = CInt(SrTxt.Text)
dr("Titles") = TitTxt.Text
dr("MediaType") = MediaTxt.Text
dr("Genre") = GenreTxt.Text
dr("Brief_desc") = DescTxt.Text
dr("Cost") = CostTxt.Text
dr("Language") = LangTxt.Text
dr("Rating") = RatingsTxt.Text
dr("Starring") = StaringTxt.Text
dr("Disc_No") = DiscTxt.Text
dr("Current_Status") = StatusTxt.Text
dt.Rows.Add(dr)
SrTxt.Enabled = True
Else
SrTxt.Text = SerialNo
GoTo SrChk
End If
ElseIf flag = 2 Then
dr.Delete()
ElseIf flag = 3 Then
dt = CollectionDataSet1.CD_DVDCollection
dr = dt.Rows.Find(SrlNo)
dr.BeginEdit()
dr("Sl_No") = CInt(SrTxt.Text)
dr("Titles") = TitTxt.Text
dr("MediaType") = MediaTxt.Text
dr("Genre") = GenreTxt.Text
dr("Brief_Desc") = DescTxt.Text
dr("Cost") = CostTxt.Text
dr("Language") = LangTxt.Text
dr("Rating") = RatingsTxt.Text
dr("Starring") = StaringTxt.Text
dr("Disc_No") = DiscTxt.Text
dr("Current_Status") = StatusTxt.Text
dr.EndEdit()
SrTxt.Enabled = True
End If
Me.CD_DVDCollectionTableAdapter.Update(CollectionDataSet1.CD_DVDCollection)
SrTxt.Enabled = False
TitTxt.Enabled = False
MediaTxt.Enabled = False
GenreTxt.Enabled = False
DescTxt.Enabled = False
CostTxt.Enabled = False
LangTxt.Enabled = False
RatingsTxt.Enabled = False
StaringTxt.Enabled = False
DiscTxt.Enabled = False
StatusTxt.Enabled = False
flag = 0
MsgBox("Updated")
End Sub
Please let me know where I am going wrong.
Regards
Sudhir