Jump to content
  • Advertisement
Sign in to follow this  

[.net] VB.Net Database Problem

This topic is 3837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

    Public Sub CheckSkills(ByVal usr As User)
        Dim ID As String = FrmSever.PlayersTableAdapter.GetData.Item(usr.UserRow).ID
        If FindSkillRowByOwner(usr.UserName) = -1 Then
            If FindSkillRowByID(ID) = -1 Then
                Dim NewSkill As Server.serverdataDataSet.SkillsRow = FrmSever.ServerdataDataSet.Skills.NewSkillsRow
                NewSkill.ID = ID
                NewSkill.Owner = usr.UserName
            End If
        End If
        Dim Row As Integer
        Row = FindSkillRowByID(ID)
        If FrmSever.ServerdataDataSet.Skills.Item(Row).MaxStr = Nothing Or FrmSever.ServerdataDataSet.Skills.Item(Row).MaxStr >= 0 Then
            FrmSever.ServerdataDataSet.Skills.Item(Row).MaxStr = ClassData(GetPlayerClass(usr)).BaseStr
            FrmSever.ServerdataDataSet.Skills.Item(Row).Str = ClassData(GetPlayerClass(usr)).BaseStr
        ElseIf FrmSever.ServerdataDataSet.Skills.Item(Row).MaxDef = Nothing Or FrmSever.ServerdataDataSet.Skills.Item(Row).MaxDef >= 0 Then
            FrmSever.ServerdataDataSet.Skills.Item(Row).Def = ClassData(GetPlayerClass(usr)).BaseStr
            FrmSever.ServerdataDataSet.Skills.Item(Row).MaxDef = ClassData(GetPlayerClass(usr)).BaseStr
        End If
    End Sub
That is supposed to check that when a person logs on to the server that all their database information is set up. When I try to log into an account who doesn't have a skills row setup it works fine with the FindSkillsRowByOwner(usr.username) = -1. That works by going through all the rows in the database and seeing if the user owns one of them, and if the user doesn't then i makes it a row. So the row is there but my problem area is this line
 FrmSever.ServerdataDataSet.Skills.Item(Row).MaxStr = Nothing
because it is saying that is DBNull. I made the database in access and it is an integer and I set it to have a default value of 0. When I view the database in access it shows the 0's but when I look at my datagrid on the server interface it shows them as empty. So I am not sure on what to do to fix this, any suggestions would be great.

Share this post

Link to post
Share on other sites
"Nothing" is not going to be a valid check against the database. If you want to change it to a valid check you want:

If FrmSever.ServerdataDataSet.Skills.Item(Row).MaxStr = DBNull.Value

although if you set it to have a default value of 0 then you shouldn't have to bother checking for a null value.

You might also want to verify that updating the database means you're getting valid data back from the call to FindSkillRowByID.

Share this post

Link to post
Share on other sites
I for when a user logs on and I added a new skilled a new skill before then, it will setup the values in the database to whatever they should be. And then when the user logs on again, its sees the values are setup and leaves them alone. This way all the values are initiated and checked at log in so they don't have to be check later on (database searches take alot of server time, so i figure get it all done at once). Ok so I don't know why it says its not there because the FindSkillRowByOwner is this.

Public Function FindSkillRowByOwner(ByVal Owner As String)
Dim I As Integer = 0
Dim Name As String = FrmSever.SkillsTableAdapter.GetData.Item(I).Owner.ToLower
Do While Name <> Owner.ToLower
I = I + 1
Name = FrmSever.SkillsTableAdapter.GetData.Item(I).Owner.ToLower
Return I
Catch ex As Exception
Return -1
End Try
End Function

So if the row isn't there then the FrmSever.SkillsTableAdapter.GetData.Item(I).Owner.ToLower line will through an exception sending a value of -1 back. But it is returning 0 because as in my previous post you can see where the row doesn't exist and then it initiates and gives it an ID and Owner. So the row is there but now I got pasted the =nothing problem.

FrmSever.ServerdataDataSet.Skills(Row).Def = ClassData(GetPlayerClass(usr)).BaseDef

So Row has been returned as 0, since it has been verified to exist. BUT! i get an exception saying there is no row 0. So I don't know what is happening, I basically copied the code from my other 3 tables that work just fine using this code.

Share this post

Link to post
Share on other sites
First of all I almost never code in VB so if I mess up a little syntax cut me some slack. I do know how to work in ADO though.

You are really trying to do a lot of work you don't need to be doing. You are trying to make this a lot harder then it really is.

First you need to make sure that in the Skills table that User is the primary key.

Public Sub CheckSkills(ByVal usr As User)
Dim userSkill As Server.serverdataDataSet.SkillsRow
userSkill = FrmSever.ServerdataDataSet.Skills.Rows.Find(usr)
If userSkill = null then
// add your new skill
Else Then.
// use userSkill to read the data you need.
End if
End Sub

That should be much easier to do then what you are doing. It is also a heck of a lot quicker.


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!