Table doesn't update - What am I doing wrong?

VB.NET

    Next

  • 1. Listview Itemcheck missing
    In VB6 we had listview1_itemcheck this would respond both to mouse clicks and also if the cursor was run up and down the control. I can't seem to find a property to do the latter. -Jerry
  • 2. insert file in word document from vb.net
    Hi, I have a vb.net program from wich i want to open a ms word-doc and insert an other document into it. But i want it to work on every version of word (minimum word 2000). can anyone help me out here?
  • 3. Not modify global value in VB.NET
    Hi I have a mutithreading application in VB.NET. In one function i stored some data in dictionaries. i declared global value to store data in dictionaries. Every time dictionary pointer has incremented. for example :public indx as integer dic.additem(indx(i)) After stored in dictionaries,i started a new thread. That new thread executes another function. I was used those dictionary values in that function. By using for loop i retrieved dictionary values. so ever time dictionary value has changed. But in the thread started function,the value has not changed. What is the reason for not changing the dictionary pointer? If anyone knows please let me know. Mamatha
  • 4. How to clone a collection?
    I have to collection that stores the items from the same class. I want to copy the items of the second collection to the first one , and empty the second. first.clean() first=second second() causes an error in the program , it seems when i clear the second one , alse referances in the first one also empties. Anyway to clone these? thank you

Table doesn't update - What am I doing wrong?

Postby Gary Paris » Mon, 18 Apr 2005 05:12:28 GMT

I have a form that has three textboxes on.  I want to be able to modify the 
FirstName, LastName, and Address

Here is the code to load the data
----------------------------------------------------------------------------
   Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles MyBase.Load

        Dim strSQL As String = "Select * from Contact where sysid = '" & 
g_sysID & "'"
        DB = New SqlClient.SqlDataAdapter(strSQL, CN)
        ES.Clear()
        DB.Fill(ES, "Contact")

        If ES.Tables("Contact").Rows.Count > 0 Then
            txtAddress.Text = 
ES.Tables("Contact").Rows(0).Item("con1_02_03")
            txtFirst_Name.Text = 
ES.Tables("Contact").Rows(0).Item("First_Name")
            txtLast_Name.Text = 
ES.Tables("Contact").Rows(0).Item("Last_Name")
        End If

    End Sub
--------------------------------------------------------------------------
Here is the code to update the table
--------------------------------------------------------------------------
   Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles btnUpdate.Click

        Try
            es.Tables(0).Rows(0).Item("First_Name") = txtFirst_Name.Text
            es.Tables(0).Rows(0).Item("Last_Name") = txtLast_Name.Text
            es.Tables(0).Rows(0).Item("con1_02_03") = txtAddress.Text
            ES.AcceptChanges()
            DB.Update(ES, "Contact")

        Catch ex As Exception

            MessageBox.Show(ex.Message)

        End Try

    End Sub
-----------------------------------------------------------------
Why doesn't the table update?  Can anyone give me an explanation and also if 
I need to change code, please tell me where to put the modifications?

Thanks,

Gary



RE: Table doesn't update - What am I doing wrong?

Postby Q2hhcmxpZQ » Mon, 18 Apr 2005 05:35:01 GMT

You should start the update routine by making a call to MyDataRow.BeginUpdate
Then add the lines that create the changes, followed by 
MyDataRow.AcceptChanges.

If you look at the fourth implementation of DataRow, you will see a second 
parameter called DataRowVersion.  The last item in that enum is Proposed.

(You can create and step through some code to test the values of the various 
DataRowVersions to see exactly what is happening.)

When you first make the change, the value is changed only for "Proposed".
When you call AcceptChanges, the Proposed value becomes the "Current" value.

When complete, call MyDataRow.EndEdit.

Of course, this only affects the DataTable, not the database.  Changes to 
the database will only be happen when you execute an UPDATE statement.

www.charlesfarriersoftware.com








Re: Table doesn't update - What am I doing wrong?

Postby Gary Paris » Mon, 18 Apr 2005 05:49:58 GMT

i Charlie,

Thanks for the reply but I don't understand a few things. Where do I put
MyDataRow.BeginUpdate? I don't have a MyDataRow defined. Do I need to
specifically define a datarow?

What does "the fourth implementation of DataRow" mean? I have no idea.

Sorry but I am a beginner and need more explicit guidance. If you could put
the changes into my code that would help lots.

Thanks,

Gary


"Charlie" <cfarrier at charlesfarriersoftware.com> wrote in message
news: XXXX@XXXXX.COM ...



RE: Table doesn't update - What am I doing wrong?

Postby Q2hhcmxpZQ » Mon, 18 Apr 2005 05:51:08 GMT

Your DataAdapter.Update command needs to have an UpdateCommand property set 
for DataAdapter.Update to execute.

I find it easier and more straightforward to just concatenate the UPDATE 
statement in code, assign it to a new command, and execute the Command with 
MyCommand.ExecuteNonQuery.






Re: Table doesn't update - What am I doing wrong?

Postby Gary Paris » Mon, 18 Apr 2005 05:55:56 GMT

Can you give me an example of how to do that?

Thanks,

Gary









RE: Table doesn't update - What am I doing wrong?

Postby Q2hhcmxpZQ » Mon, 18 Apr 2005 05:56:02 GMT

Also, when you put together the UPDATE statement, be sure to include the 
WHERE clause.  Otherwise, you will update every record, and essentially 
destroy your data.  I don't want to insult your intelligence, but it's an 
easy mistake to make, and worth noting.





Re: Table doesn't update - What am I doing wrong?

Postby Q2hhcmxpZQ » Mon, 18 Apr 2005 05:59:01 GMT

yDataRow just means the datarow you are using:
ES.Tables("Contact").Rows(0).

When you see My used this way, it just means "your instance", as opposed to
a shared member of an object, such as String.Join...

"Gary Paris" wrote:


Re: Table doesn't update - What am I doing wrong?

Postby Q2hhcmxpZQ » Mon, 18 Apr 2005 06:08:04 GMT

ou could adapt this. You can get the exact syntax of the UPDATE statement
through various sites, in case I have a typo here...

Dim UPDATE As String = "UPDATE MyTable SET FirstName = '" &
txtFirstName.text & "' LastName = " & txtLastName.text & " WHERE PrimaryKey =
1"
Dim CMD As New OleDb.OleDbCommand(UPDATE, MyConnection)
MyConnection.Open()
CMD.ExecuteNonQuery()
MyConnection.Close()

"Gary Paris" wrote:


Re: Table doesn't update - What am I doing wrong?

Postby Cor Ligthert » Mon, 18 Apr 2005 17:07:44 GMT

Gary,

There are at least two things what makes that your update does not work.
You are have no commands in your dataadapter.
You use the acceptchanges wrong.

I have made some corrections typed (so watch typos) inline in this message 
so look below to them.

You better create and dispose better as well the connection in those 
procedures because now you don't free the connectionpool.


dim cb as new sqlclient.sqlcommandbuilder(db)




delete the row above, this means that all rowstates which are set to a 
changed state will be set to unchanged and the changes are accepted, so the 
dataadapter has nothing to change. It is implicitly done by the dataadapter 
when a change is done.


I hope this helps,

Cor 



Re: Table doesn't update - What am I doing wrong?

Postby Robert Payne » Tue, 19 Apr 2005 00:53:09 GMT

Gary,

When you execute the Update method for the DataAdapter, it checks the 
RowStatus of each DataRow in the DataSet to determine whether to execute the 
Insert, Update, or Delete command.  Executing the AcceptChanges method on 
the DataSet resets the RowState property of all rows to Unchanged, thereby, 
making the rows appear as if they've never been modified.  Remove the 
AcceptChanges line and your database should be updated as expected.

Rob










Similar Threads:

1.What am I doing wrong - Trying to update

I have enclosed the sample code that I created.  I want to read in employee 
data, and modify a few fields.  I have tried to globally declare the objects 
that I need but I still am having problems.  I want to update in a seperate 
subroutine and seem to have problems.  HELP please.

-------------------------------------------
Public Class Form1

    Inherits System.Windows.Forms.Form
    Public cn As OleDb.OleDbConnection
    Public ds As DataSet
    Public da As OleDb.OleDbDataAdapter
    Public rowEmployee As DataRow

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

        Try
            Dim strConn As String
            strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data 
Source=C:\adonetsbs\SampleDBs\nwind.mdb;"

            Dim cn As New OleDb.OleDbConnection(strConn)

            Dim strSQL As String
            strSQL = "SELECT EmployeeID, FirstName, LastName, Address, City, 
Region, " & _
                "PostalCode from Employees ORDER BY LastName, FirstName"

            Dim da = New OleDb.OleDbDataAdapter(strSQL, strConn)
            Dim ds As New DataSet

            da.Fill(ds, "Employees")

            Dim tbl As DataTable = ds.Tables(0)

            'rowEmployee = New DataRow
            rowEmployee = tbl.Rows(0)
            txtFirstName.Text = rowEmployee("FirstName")
            txtLastName.Text = rowEmployee("LastName")
            txtAddress.Text = rowEmployee("Address")

        Catch ex As Exception
            MessageBox.Show(ex.Message & " :: " & ex.Source)
        Finally
        End Try
    End Sub

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles btnUpdate.Click
        Try
            rowEmployee("LastName") = txtLastName.Text
            da.Update(ds)

        Catch ex As Exception

            MessageBox.Show(ex.Message & " :: " & ex.Source)

        End Try

    End Sub
End Class
---------------------------------------

When it runs I get the following error:

"Object reference not set to an instance of an object."

on the             da.Update(ds)       line in the btnUpdate_Click routine.

HELP.

Thanks,

Gary


2.What am I doing wrong??

Here is what I am trying:

My.Computer.FileSystem.CopyFile("\\server\all\sets\!!!!!PREFS
\Application Data", _
"C:\Documents and Settings\" & Environment.UserName & "\Application
Data\Adobe", True)
        MessageBox.Show("Done Resetting Application Data, Press OK to
Continue and reset Local Settings data", "Backup in progress...",
MessageBoxButtons.OKCancel, MessageBoxIcon.Information)
        My.Computer.FileSystem.CopyFile("\\server\all\sets\!!!!!PREFS
\Local Settings", _
"C:\Documents and Settings\" & Environment.UserName & "\Local Settings
\Application Data\Adobe", True)
        MessageBox.Show("Done Resetting Local Settings data, Press OK
to Continue.", "Backup in progress...", MessageBoxButtons.OK,
MessageBoxIcon.Information)

I get the error that: \\server\all\sets\Application Data  is not
found, but it is there, and inside that folder I want to copy a folder
to c:\doc and set\user\application data\adobe

Also, will this work like this, one statement after another to do two
things?

thanks

3.Project build problem - what am I doing wrong?

I have a program that needs to access a prewritten external data file
that is supplied with the program. I want to place this data file in
Environment.SpecialFolder.LocalApplicationData\MyProgramFolder\

In the program's setup project I've done: Add Special Folder | User's
Application Data File, then within this created a folder called
MyProgramFolder, then Add File and pointed to a copy of my external
data file, which duly appears in the folder contents (EXCEPT that it
has a wavy line underneath!)

But unfortunately the resulting setup program does not install the
external data file where it should - in fact as far as I can see it
does not install it at all anywhere on the target PC.

Cany anyone advise what I'm doing wrong please? The fact that the file
entry has a wavy line underneath is presumably indicative of an error
but what's the cause and how do I fix it?

JGD

4.Newbe question, What am I doing wrong

Hi,
I have two questions the first is: in the example below how can I call
an event from within a statement, such as replace Stop1 with cmdStop1
which is a button on my form?
My second question again deals with the example below. Shouldn't I see
the valve of " i" counting away in the  txtCount1 text box? I don't
see anything in the text box and would like to know what I'm doing
wrong. Thanks in advance for any and all help.
Regards,
Ken



 Stop1 = 0
        Do
            For i As Integer = 1 To 10
                txtCount1.Text = i
                If Stop1 = 1 Then
                    Exit Do
                End If
            Next i
        Loop
    End Sub

5.Programatically getting a RichTextBox to scroll - What Am I doing Wrong

Ive been working on this since yesterday and its bugging me. Although the
event is firing, The box does not scroll. Can anyone see what Im doing
wrong. I suspect it is stupidly simple.



TIA



SubClass RichtextBox in order to fire the OnVScroll Event

Public Class MyRichTextBox

Inherits RichTextBox

Public Sub PerformVScroll()

MyBase.OnVScroll(EventArgs.Empty)

End Sub

End Class

- This button invokes the PerformVScroll -

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles PerformVscroll.Click

RTB.PerformVScroll()

End Sub

- THis confirms that the event has been raised -

Private Sub handleScroll(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles RTB.VScroll

Console.WriteLine("Handling scroll")

End Sub




-- 
Regards - One Handed Man

Author : Fish .NET & Keep .NET
=========================================
This posting is provided "AS IS" with no warranties,
and confers no rights.



6. What am I doing wrong?

7. What am i doing wrong?

8. What am I doing wrong?



Return to VB.NET

 

Who is online

Users browsing this forum: No registered users and 30 guest