TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
viviansm
NA
21
0
Auto number
Jun 17 2004 4:37 AM
Good day. I am a beginner in VB.NET. I have a problem that I used (TheTable.Rows.Count + 1) to generate the no. for the customer ID. If I deleted some of the records and then add a new records, the customer ID will not correct. This is because I am using TheTable.Rows.Count + 1, what I can do to solve this problem? How do check the last customerID in the Customer table in SQL server? can this solve my problem? I am using ADO.net. The code i am writing is : Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click SqlDataAdapter1.Fill(Me.DataSet11, "Customer") Dim TheTable As DataTable = Me.DataSet11.Tables(0) Dim aRow As DataRow = TheTable.NewRow() txtCustID.Text = TheTable.Rows.Count + 1 ClearForm() txtCustName.Focus() end sub Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Try Dim TheTable As DataTable = Me.DataSet11.Tables(0) Dim aRow As DataRow = TheTable.NewRow() aRow("CustID") = TheTable.Rows.Count + 1 aRow("CustName") = txtCustName.Text aRow("CustAdd") = txtAdd.Text aRow("Postcode") = txtPostcode.Text aRow("City") = txtCity.Text TheTable.Rows.Add(aRow) SqlDataAdapter1.Update(Me.DataSet11, "Customer") txtCustID.Text = aRow("CustID") MessageBox.Show("Customer Was Successfully Added ", "VIP", MessageBoxButtons.OK, MessageBoxIcon.Information) txtCustID.Text = TheTable.Rows.Count + 1 ClearForm() txtCustName.Focus() Catch ex As Exception MessageBox.Show(ex.Message.ToString()) End Try End Sub If you know how to solve this problem, please post! Thanks in advance and best regards, viv
Reply
Answers (
4
)
Using the query Analyzer for sql server 2000.
simple binding