Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27154

DataGridView/Database Error - Help!

$
0
0
I've been getting an odd, elusive error randomly throughout the creation of my movie manager program. Sometimes, when I go to run the program, it doesn't have any of the data that's been saved. It'll just be a blank datagridview. Then I'll run it later and it'll have the data. Now, it's gotten worse, because I have all these functions/subs that rely on the datagridview to have data, and if it doesn't, my program won't even load because none of the functions/subs have any data to use.

I know I need to code for the possibility of no data so my program doesn't crash since having no data is a valid option with my program if a new user is created. But this error is driving my crazy because it's not a consistent error and I have NO idea why it'll not have any data when the program is loaded sometimes. It seems once I get the error, it stays that way after multiple program runs. So I have a couple questions:
1) Does anybody know why this can be?
2) Where is data stored? I believe I have a data-bound datagridview. In my Solution Explorer, I have a Database1.sdf & a Database1.DataSet.xsd (← I was thinking the data is stored in this while the Database1.sdf just holds the schema). The funny thing is when I go to click on or try to open Database1.DataSet.xsd, I just get an error message saying that Database1.DataSet.xss cannot be found (notice the .xss vs the .xsd).

I don't want to post too much code up here but here's how the program is loaded after logging in. Login.vb (VB.NET):
Code:

Public Class login
    ' Login
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Me.Database1Dataset.Users.
        Dim row As DataRow
        Globals.GlbUserName = ""
        For Each row In Database1DataSet.Users.Rows
            If row.Item("Username").ToString = TextBox1.Text And row.Item("Password").ToString = TextBox2.Text Then
                Globals.GlbUserName = TextBox1.Text
            End If
        Next
        If Globals.GlbUserName <> "" Then
            Me.Hide()
            Form1.Show()
            Form1.SetForm()
        Else
            MessageBox.Show("Username or Password not found.")
        End If
    End Sub

    Private Sub UsersBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.UsersBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.Database1DataSet)

    End Sub

    Private Sub login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.UsersTableAdapter.Fill(Me.Database1DataSet.Users)
    End Sub

    ' Register
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Database1DataSet.Users.AddUsersRow(TextBox1.Text, TextBox2.Text)
        Me.TableAdapterManager.UpdateAll(Me.Database1DataSet)
        GlbUserName = TextBox1.Text
        Form1.Show()
    End Sub
End Class

Here's just some of Form1.vb:
Code:

Public Class Form1

    Private Sub FilmsBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.FilmsBindingSource.EndEdit()
        Me.FilmsTableAdapter.Update(Database1DataSet)
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.FilmsTableAdapter.Fill(Me.Database1DataSet.Films)
        Me.FilmsTableAdapter.Fill(Me.Database1DataSet.Films)
        Me.FilmsTableAdapter.Fill(Me.Database1DataSet.Films)
        Me.FilmsBindingSource.Filter = "Username = " + Globals.GlbUserName
    End Sub

    ' Adds new row to database & datagridview
    Private Sub FilmsBindingSource_Addingnew( _
        ByVal sender As Object, _
        ByVal e As System.ComponentModel.AddingNewEventArgs)
        Dim dataTableView As DataView = FilmsBindingSource.List
        Dim rowView As DataRowView = dataTableView.AddNew
        rowView.Item("Username") = GlbUserName
        e.NewObject = rowView
    End Sub


Viewing all articles
Browse latest Browse all 27154

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>