Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 26th, 2007, 04:18 AM
Registered User
 
Join Date: Nov 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL DataGridView not updating afer a change

I have a SQL table in a program which I import the lottery CSV file off the internet. I also delete the data in the table before importing the file. However, when I run the project or if I publish it. Any imports or delete are not seen when I open a form with a data grid view. I have to stop debugging the project or if I am running the program close it down. When I am debugging it again or start the program the changes are there.

I know the the data mdf are in two places when I working on the project. That not true if I published it, or is it?

Where Am I going wrong.


Delete code

Private Sub ClearLotteryTableToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearLotteryTableToolStripMenuItem.Click
        Dim objConnection As SqlConnection = New _
                               SqlConnection()

        objConnection.ConnectionString = _
                "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\ellip\My Documents\VB\My Work\VBproagam\DatabaseWork\LotteryVB1\Lotterytest 1\Lotterytest1\LotteryTestDatabase.mdf;" & _
                "Integrated Security=True;Asynchronous Processing=true;Connect Timeout=30;User Instance=True"
        Dim objCommand As SqlCommand = New SqlCommand()
        objConnection.Open()

        objCommand.Connection = objConnection
        objCommand.CommandText = "DELETE FROM LotteryNumbers"

        objCommand.ExecuteNonQuery()
        objConnection.Close()
        Me.LotteryNumbersTableAdapter.Update(Me.LotteryTes tDatabaseDataSet.LotteryNumbers)
        'TODO: This line of code loads data into the 'LotteryTestDatabaseDataSet.LotteryNumbers' table. You can move, or remove it, as needed.
        Me.LotteryNumbersTableAdapter.Fill(Me.LotteryTestD atabaseDataSet.LotteryNumbers)

    End Sub

Load Form code.

 Private Sub frmLotteryNumbers_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LotteryTestDatabaseDataSet.GetChanges()

        LotteryNumbersDataGridView.Refresh()

        loadNumbersLotteryTable()

    End Sub

    Public Sub loadNumbersLotteryTable()
        ' Change header text

        LotteryNumbersDataGridView.Columns(10).Width = 265
        LotteryNumbersDataGridView.Columns(0).HeaderText = "Draw Date"
        LotteryNumbersDataGridView.Columns(1).HeaderText = "Ball One"
        LotteryNumbersDataGridView.Columns(2).HeaderText = "Ball Two"
        LotteryNumbersDataGridView.Columns(3).HeaderText = "Ball Three"
        LotteryNumbersDataGridView.Columns(4).HeaderText = "Ball Four"
        LotteryNumbersDataGridView.Columns(5).HeaderText = "Ball Five"
        LotteryNumbersDataGridView.Columns(6).HeaderText = "Ball Six"
        LotteryNumbersDataGridView.Columns(7).HeaderText = "Bonus Ball"
        LotteryNumbersDataGridView.Columns(8).HeaderText = "Ball Set"
        LotteryNumbersDataGridView.Columns(9).HeaderText = "Machine"
        LotteryNumbersDataGridView.Columns(10).HeaderText = "Draw Data"

        ' Declaire and set alternating row style
        Dim objAlternatingCellStyle As New DataGridViewCellStyle()
        objAlternatingCellStyle.BackColor = Color.LightSkyBlue

        LotteryNumbersDataGridView.AlternatingRowsDefaultC ellStyle = objAlternatingCellStyle
        Me.LotteryNumbersTableAdapter.Update(Me.LotteryTes tDatabaseDataSet.LotteryNumbers)

        'TODO: This line of code loads data into the 'LotteryTestDatabaseDataSet.LotteryNumbers' table. You can move, or remove it, as needed.
        Me.LotteryNumbersTableAdapter.Fill(Me.LotteryTestD atabaseDataSet.LotteryNumbers)

        Dim newColumn As DataGridViewColumn

        newColumn = Me.LotteryNumbersDataGridView.Columns(0)


        Me.LotteryNumbersDataGridView.Sort(newColumn, ComponentModel.ListSortDirection.Descending)

    End Sub

 
Old May 28th, 2007, 08:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there.. how are you connecting the grid with the database???, you are only filling it on the load event???

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old May 29th, 2007, 04:55 PM
Registered User
 
Join Date: Nov 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,
   I just used the drag and drop to drop the lotteryNumbers table to a form from data sources. Easy why to create something you don't fully under stand. Soon as you run the prject the DataGridView is full of data.

Because the data is clear or reloaded with data, depending if I have import CSV or deleted data in to the table. After a program restart or debug (stop/start). Some thing is cleared of data. Was looking at the book again is data Binding?

I am just loading the datagridview as you pointed out. What do I also have to do. After a CSV load or Delete,to see the true data state of the table?
 
Old May 30th, 2007, 08:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

you have to refresh the grid so it will refill it..

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old May 31st, 2007, 02:50 PM
Registered User
 
Join Date: Nov 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Refill, how???
 
Old May 31st, 2007, 02:56 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

for the sake of simplicity, just call again: loadNumbersLotteryTable() after you load the cvs file..

(but i think that you only need to do: LotteryNumbersDataGridView.Refresh())

you only need to rebind the grid, but since you are ordering it and do a lot of other stuff just call that and you will see the new data, in other words, you have to do the same as you do when you load the form...

HTH

Gonzalo

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
WORKS ON MY MACHINE
http://www.codinghorror.com/blog/archives/000818.html
================================================== =========
I know that CVS was evil, and now i got the proof:
http://worsethanfailure.com/Articles...-Hate-You.aspx
================================================== =========
 
Old June 4th, 2007, 04:06 PM
Registered User
 
Join Date: Nov 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I found the problem, it was all to do with the two database file (mdf). I moved the main mdf that was not in the bin directory, to a new location. Found all the setting that I had to change in Visual Studio. The DataGridView update OK now.





Similar Threads
Thread Thread Starter Forum Replies Last Post
updating SQL tables leopardj Beginning PHP 2 January 29th, 2007 06:42 AM
Add records from a DataGridView to SQL Server 2000 VS2005 Visual Basic 2005 Basics 2 November 27th, 2006 08:32 AM
Updating data in a subform when tables change. Paulsh Access VBA 1 October 6th, 2004 03:49 PM
Updating to SQL Database Arsi Classic ASP Databases 4 August 23rd, 2004 12:48 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.