Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello All

I have a CD collection program that the user can click through a list(database) of CDs - I have some filters that the user can choose also ie "By Title" - I would also like to have an Add menu item which I started but the problem is that on of the fields in the database (CdKey) is one that the user should not worry about but is crucial that I update it or add one(1) to the last CDkey number ie their are 100 records lets say and obviously the CDkeys are 1-100. How do I include this in the add code?

 

Private Sub mnuAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuAdd.Click
       BindingContext(DbCdCollection1, "Cds").AddNew()
   ' CDKEY= SOMETHING HERE??????
       UpdateCounter()
   End Sub


 

my fields are:CdArtist,CdTitle, CdYear,CdKey,CdCategory

Thanks

Rob

Posted

Do you mean in the database itself? We talked about that and our teacher said that since we used the Wizard to connect the dataadapter etc... that sometimes it does not do that properly especially if we delete a record which is one of the menu items I have - he said we shoud put it in the code as in the above.

 

 

thanks

ROb

Posted

Well the best idea is to use the auto increment in the database, it reliefs you. The Auto Increment is almost a necessity when developing Multi User applications. However In Access the auto increment is some what erraneous ....

 

Moreover if only one user is using your application you can manage to work it out yourself. So i guess in your case Rob only one will be running your application (A school project you said).

 

So what you should do is use this Sql statement to get the Max Id from the database

'I guess you know how to connect to a database (you have done that already)
'declare an oledb command
Dim GetIdCommand as New OleDbCommand()
With GetIdCommand
      'set the connection to the connection you have
      .Connection = "Your Connection"
      'substitute yourt ablename here
      .CommandText = "Select IsNull(Max(Id),0) from [TABLENAME]"
End With

Dim MaxId as integer = Convert.ToInt32(GetIdCommand.ExecuteScalar())

'Now you have the Max ID from the database

CDKEY = MaxId + 1

 

Hope this helps,

Dream as if you'll live forever, live as if you'll die today

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...