Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Wednesday, May 15, 2024 
 
slxdeveloper.com Community Forums  
   
The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
 External Development Forums - SalesLogix OLEDB Provider
Forum to discuss using the SalesLogix OLE DB Provider from external applications (including usage of built-in provider procedures). View the code of conduct for posting guidelines.
Forums RSS Feed


 Back to Forum List | Back to SalesLogix OLEDB Provider | New ThreadView:  Search:  
 Author  Thread: Inserting records with lots of fields
Mark Hanford
Posts: 131
 
Inserting records with lots of fieldsYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 01 Dec 08 11:25 AM
Hello,

I'm using the provider with 7.2, and am hitting a problem with inserts.

So far, I've been using prepared statements, like example 1 below, and this works fine. The problem comes when inserting into large tables (Eventix anyone? ) At which point keeping track of all the ?'s and parameter add sequence gets somewhat risky. Trouble is, I can't seem to get .add to work, is that limited by the provider, or by me making errors? :D

So, couple of questions really:
1. Are prepared statements like Ex.1 the best way?
2. Can dataadapters be used like Ex.2?
3. Can I use named-parameters instead of a big list of "?" ?

Thanks,

Mark


Example 1 (works, but unscalable with 80+ fields):
Sql = "INSERT INTO mytable (field1, field2, field3) VALUES (?, ?, ?)"
Dim cmd As New OleDbCommand(Sql, _con)
cmd.Parameters.AddWithValue("@", MyVal1)
cmd.Parameters.AddWithValue("@", MyVal2)
cmd.Parameters.AddWithValue("@", MyVal3)
cmd.ExecuteNonQuery()


Example 2 (can't get this to work)
Sql = "SELECT * FROM EVXEVRESV WHERE 1=0"
Dim da As OleDbDataAdapter = New OleDbDataAdapter(Sql, _con)
Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(da)
Dim ds As New DataSet
da.Fill(ds, "EVXEVRESV")
Dim dr As DataRow = ds.Tables("EVXEVRESV").NewRow
dr("EVXEVRESVID") = EVXEVRESVID
dr("FIELD1") = Val1
dr("FIELD2") = Val2
...
dr("FIELDn") = Valn
ds.Tables("EVXEVRESV").Rows.Add(dr)
[Reply][Quote]
Mark Hanford
Posts: 131
 
Re: Inserting records with lots of fieldsYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 01 Dec 08 11:38 AM
I forgot to mention, I get no errors with method 2, it just silently doesn't add any records.

Also, a fairly rudimentary example of my method 2 can be found at http://www.cylindric.net/bin/jyfdn
[Reply][Quote]
Phil Parkin
Posts: 819
Top 10 forum poster: 819 posts
 
Re: Inserting records with lots of fieldsYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 01 Dec 08 4:01 PM
Method 2 definitely works - I just think you've got a bit missing from the end:

da.Update(ds.GetChanges)
ds.AcceptChanges

or similar.

Phil
[Reply][Quote]
Mark Hanford
Posts: 131
 
Re: Inserting records with lots of fieldsYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 02 Dec 08 4:22 AM
Brilliant! That got me in the right direction, thanks a lot

For future reference, here's a working example. (The connection is already established elsewhere, and referenced by slx._con, the Account and Contact that are passed in simply contain the fields for those, and EVXEVRESVID is a primary key that I looked up previously)


Private Sub AddFreeReservation(ByVal EVXEVRESVID As String, ByVal Account As AccountClass, ByVal Contact As ContactClass)
Dim Sql As String = ""
Dim cmd As New OleDbCommand(Sql, slx._con)

Dim Sql As String = "SELECT * FROM EVXEVRESV WHERE 1=0"
Dim da As OleDbDataAdapter = New OleDbDataAdapter(Sql, slx._con)
Dim cb As OleDbCommandBuilder New OleDbCommandBuilder(da)
Dim ds As New DataSet
da.Fill(ds, "EVXEVRESV")

Dim dr As DataRow = ds.Tables("EVXEVRESV").NewRow
dr("EVXEVRESVID") = EVXEVRESVID
dr("CREATEUSER") = Me.fld_CREATEUSER
dr("CREATEDATE") = Me.fld_CREATEDATE
dr("MODIFYUSER") = Me.fld_MODIFYUSER
dr("MODIFYDATE") = Me.fld_MODIFYDATE
dr("RESVMADEBYCONTACT") = String.Format("{0} {1}", Contact.FirstName, Contact.LastName)
dr("RESVMADEBYCONTACTID") = Contact.ContactID
dr("RESVTYPE") = ""
dr("RESVSTATUS") = ""
dr("RESVMADEBYACCOUNT") = Account.Account
dr("RESVMADEBYACCOUNTID") = Account.AccountID
dr("REVIEWREQUIRED") = "F"
dr("REVIEWTYPE") = ""
dr("REVIEWDESC") = ""
dr("REVIEWBYDATE") = DBNull.Value
dr("REVIEWUSER") = ""
dr("REVIEWUSERID") = ""
dr("RESVFOLDERNAME") = String.Format("{0}, {1} | {2}", Contact.LastName, Contact.FirstName, Account.Account)
dr("CURRENCYTYPE") = "GBP"
dr("COMMENTS") = ""
ds.Tables("EVXEVRESV").Rows.Add(dr)
da.Update(ds.Tables("EVXEVRESV").GetChanges)
ds.AcceptChanges()

End Sub

[Reply][Quote]
RJ Samp
Posts: 973
Top 10 forum poster: 973 posts
 
Re: Inserting records with lots of fieldsYour last visit to this thread was on 1/1/1970 12:00:00 AM
Posted: 04 Dec 08 12:51 PM
Am a little lost on this, but am liking what I see!

1. what is the Me. object? Where/How is it established?
2. While we're on Me.....since this is going through the SLX OLE DB Provider, why are You updating CreateDate, et al? not necessary.
3. how do you get those pretty references to Account, Contact.....is that through a Global class object ? How do you set that up?

Thanks!
[Reply][Quote]
 Page 1 of 1 
  You can subscribe to receive a daily forum digest in your user profile. View the site code of conduct for posting guidelines.

   Forum RSS Feed - Subscribe to the forum RSS feed to keep on top of the latest forum activity!
 

 
 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 5/15/2024 9:01:16 AM