Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
ingineu
Yak Posting Veteran
89 Posts |
Posted - 2003-07-06 : 01:11:22
|
I'm trying to figure out the best method of updating a SQL database from an Access 2000 project using ADO. I edit fields entered on a Form in Visual Basic. Upon acceptance I Add, or Change the Record.This is my code so far:Set Comm1 = Application.CurrentProject.ConnectionSet Rst1 = New ADODB.RecordsetRst1.Open "tblTest",Comm1,adOpenKeyset,adLockOptimistic,adCmdTablestrKey = "[Fld1] = 'Test'"Rst1.Find strKey, , adSearchForwardIf Rst1.EOF ThenRst1.AddNewRst1("Fld1") = "Test"Rst1("Fld2") = ...... etc.Rst1.UpdateElseMsgBox "Record already exists", vbInformation + vbOKOnly, "ERROR"Rst1.CloseComm1.CloseSet Rst1 = NothingSet Comm1 = NothingExit SubEnd IfRst1.CloseComm1.CloseSet Rst1 = NothingSet Comm1 = Nothing Should I rather use a Stored procedure for this action? .. Should I execute a SQL Command? ...Thanks. |
|
mohdowais
Sheikh of Yak Knowledge
1456 Posts |
Posted - 2003-07-06 : 02:45:10
|
You will be better off creating a stored proc on SQL Server and invoking that from code using an ADO Command Object. For many reasons, primarily security and speed. AdoDB.Recordset.AddNew might be a convenient method but it is quite often prone to locking and concurrency problems. You could actually do all of the code in this procedure inside a stored proc. So go for it!Owais |
 |
|
ingineu
Yak Posting Veteran
89 Posts |
Posted - 2003-07-06 : 03:27:15
|
Can you point me to any available code I can look at, as I'm new to Stored Procedures and have only done some pretty basic ones so far.Thanks. |
 |
|
mohdowais
Sheikh of Yak Knowledge
1456 Posts |
Posted - 2003-07-06 : 09:08:41
|
Look up in the Books-online that come with any SQL Server installation. Its got some good examples to get you started, and of course, there is no substitute for trial-and-error...absolutely the best way to learn. Invest in a good beginners book on programming with SQL Server with VB/VBA. There are some good resources on the web, but most of them are biased towards ASP programming, though any content on SQL Server still applies. Check out:http://www.4guysfromrolla.comhttp://www.15seconds.comTry to build the proc yourself first, its not too complicated even for a beginner. If you get stuck, yell here for help Owais |
 |
|
Doug G
Constraint Violating Yak Guru
331 Posts |
Posted - 2003-07-08 : 02:34:49
|
I take it you don't want to use databound controls on your form and give your form a recordset to work with?======Doug G====== |
 |
|
ingineu
Yak Posting Veteran
89 Posts |
Posted - 2003-07-08 : 03:22:13
|
The Data entry procedure is too complex. They can select a number of different cycles and I pickup recordsets accordingly, displaying each record in a specified sequence. I think I'm going to work with my code as is, since I do like having control in 1 spot. Should be easier for someone else to follow my code. |
 |
|
|
|
|
|
|