What am I doing wrong - Trying to update

VB.NET

    Next

  • 1. RegEx and special range metacharaacters
    Are any of the special range metacharacters allowed in RegEx operations(System.Text.RegularExpressions) . If so how could you please specify an example. Thx! sd [:digit:] Only the digits 0 to 9 [:alnum:] Any alphanumeric character 0 to 9 OR A to Z or a to z. [:alpha:] Any alpha character A to Z or a to z. [:blank:] Space and TAB characters only. [:xdigit:] . [:punct:] Punctuation symbols . , " ' ? ! ; : [:print:] Any printable character. [:space:] Any space characters. [:graph:] . [:upper:] Any alpha character A to Z. [:lower:] Any alpha character a to z. [:cntrl:] .
  • 2. Dll reference between forms
    I got an exe which include a form MDI ===> FORM A I got another dll wich include a form =====> FORM B In my FORM A I can launch FORM B and assign FORM B.MdiParent = FORM A But from FORM B I cannot launch any functions from FORM A I think that the dll (form B) have no clue about FORM A extra function other then the basic one like text , name etc. How can I refer back to FORM A from FORM B This main application is kind of modular so my main application FORM A doesn't really now how many mdiChildren it will handle assuming that today I got FORM B dll then tomorow I'll have FORM C dll etc... They all have to be able to inter connect Thanks for the help
  • 3. Adding a input mask
    I need to allow only numbers into a text box -- Cheers, Crirus ------------------------------ If work were a good thing, the boss would take it all from you ------------------------------
  • 4. Kill Idle Process
    Hi, We have a limited number of licenses to some software we have installed on our users desktops. The problem is that sometimes the users open up the application and then don't use it all day. This prevents others from being able to use the application because we run out of licenses. I'm thinking that we want to create a windows service using VB.Net that we will run on everyone's machine and have it monitor this application to see if it is idle for too long. If it is idle for too long, we will then kill it and pop up a message to the users letting them know what we did. Does anyone have any ideas? Any sample code? Thanks!

What am I doing wrong - Trying to update

Postby Gary Paris » Fri, 08 Apr 2005 00:19:58 GMT

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



RE: What am I doing wrong - Trying to update

Postby S2VycnkgTW9vcm1hbg » Fri, 08 Apr 2005 01:23:04 GMT

Gary,

In Form1_Load you are creating local variables such as da, ds, etc.

Instead, you need to use the "global" or form level variables that you have 
creted in the form's declarations section.

In Form1_Load, you just need to do something like:

     ds = New DataSet

instead of dimensioning the variable again.

Kerry Moorman






Re: What am I doing wrong - Trying to update

Postby Cor Ligthert » Fri, 08 Apr 2005 01:23:53 GMT

Gary,

There is a lot still not right, however let us first take this problem.
Your error message is strange for me, that I don't directly see.
However you needs an update command in the dataadapter.
That is easy to do for a simple select statement as you have.
See the code I have pasted inline (one row)
And try than again. I now don't understand the error you get, however that 
is at least needed.

When you have it running have than a look at
Databinding
\\\
cma = DirectCast(BindingContext(dataset1.Tables(0)), CurrencyManager)
textbox1.DataBindings.Add(New Binding("Text", dataset1.Tables(0), 
"LastName"))
///
The cma.position gives you than the row that is used and you can affect that 
by using buttons on your form.

I hope this helps,

Cor


                dim cmb as new OleDb.OleDbCommandbuilder(da)




Re: What am I doing wrong - Trying to update

Postby Cor Ligthert » Fri, 08 Apr 2005 01:26:57 GMT

Kerry,

That is it, however Gary needs my answer as well for his next problem.

:-)

Cor 



RE: What am I doing wrong - Trying to update

Postby YnJpeF96eDI » Fri, 08 Apr 2005 01:35:03 GMT

Okay, I'm going to try for a bit of a rewrite.

--------------------------------------------------------
Dim da As System.Data.OleDb.OleDbDataAdapter
Dim cn As System.Data.OleDb.OleDbConnection

cn = New System.Data.OleDb.OleDbConnection ( _
"provider=Microsoft.Jet.OLEDB.4.0; & _
data source=C:\adonetsbs\SampleDBs\nwind.mdb;"

da = New System.Data.OleDb.OleDbDataAdapter( _
"SELECT EmployeeID, FirstName, LastName, Address, City, Region, PostalCode 
FROM Employees ORDER BY LastName, FirstName"

Dim ds As System.Data.DataSet
ds = New System.Data.DataSet

cn.Fill(ds)

---------------------------------------
That will get your data adapter and dataset going.... the rest I'm having a 
bit of trouble reading.......




Re: What am I doing wrong - Trying to update

Postby Gary Paris » Fri, 08 Apr 2005 01:41:25 GMT

or,

I put the
dim cmb as new OleDb.OleDbCommandbuilder(da)
line in as you suggested. Still got the same error. Can you explain the
other command you described and where it goes? I don't understand.

Thanks,

Gary

"Cor Ligthert" < XXXX@XXXXX.COM > wrote in message
news:OW% XXXX@XXXXX.COM ...



Re: What am I doing wrong - Trying to update

Postby Gary Paris » Fri, 08 Apr 2005 01:46:41 GMT

his is OK, but how can I do an update from another subroutine when the
connection and dataadapter are not global? I want to click on a button to
do the update.

Thanks

Gary

"brix_zx2" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...



Re: What am I doing wrong - Trying to update

Postby Cor Ligthert » Fri, 08 Apr 2005 01:49:54 GMT

Gary,

See the answer from Kerry what means

              ds = New DataSet
            da.Fill(ds, "Employees")
             dim cmb as new OleDb.OleDbCommandbuilder(da)

Cor 



Re: What am I doing wrong - Trying to update

Postby Gary Paris » Fri, 08 Apr 2005 01:58:26 GMT

Cor,

I made the change and I still get the object not referenced error.

Gary








Re: What am I doing wrong - Trying to update

Postby Cor Ligthert » Fri, 08 Apr 2005 02:11:25 GMT

Gary

This ones too

 cn = New OleDb.OleDbConnection(strConn)

 da = New OleDb.OleDbDataAdapter(strSQL, strConn)

Cor



Similar Threads:

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

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


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 90 guest