Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / September 2007

Tip: Looking for answers? Try searching our database.

OnLoad Event

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dmox - 07 Sep 2007 15:20 GMT
I'm having issues with an OnLoad event.  I'm trying to update a SQL Database
when the form loads with the following code:

       Public Sub FormEvents_Loading(ByVal sender As Object, ByVal e As
LoadingEventArgs)
           ' Write your code here.
           Dim conn As New SqlConnection()
           conn.ConnectionString = "Data Source=SQL2005;Initial
Catalog=Database1;Persist Security Info=True;User ID=DBDude;Password=MyPass"
           Dim SqlConnection As String = "INSERT INTO Ticket (Ref) VALUES
('Test')"
           conn.Close()
       End Sub

It debugs and loads fine, however it's not updating the database at all.
S.Y.M. Wong-A-Ton - 09 Sep 2007 02:06 GMT
Currently, the code is not really doing any actions on the database: You set
the connection string, but don't open the connection. Then you declare a
SqlConnection as a string and don't do anything with it. And then you just
close the connection...

You need to create and use a SqlCommand object and then execute the INSERT
statement using the ExecuteNonQuery() method on the command (see
http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.execut
enonquery(vs.80).aspx
).
---
S.Y.M. Wong-A-Ton

> I'm having issues with an OnLoad event.  I'm trying to update a SQL Database
> when the form loads with the following code:
[quoted text clipped - 11 lines]
>
> It debugs and loads fine, however it's not updating the database at all.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.