i want to add a record to a table via storedprocedure. i did a stroedprocedure in sqlserver. it runs well. how can i use the stored procedures in vb6.0? stored procedure; CREATE PROCEDURE dbo.addNewRow ( @S_CID int, @S_Desc nvarchar(255) ) AS INSERT INTO tblDummy ( S_CID, S_Desc, S_Date ) VALUES ( @S_CID, @S_Desc, GETDATE() ) GO (moved from General DBA section to here due to topic relevancy)
Review this linkhttp://www.macronimous.com/resources/stored_procedures_for_ASP_and_VB_Programmers.asp for more explanation about the subject. Satya SKJ Moderator http://www.SQL-Server-Performance.Com/forum This posting is provided “AS IS†with no rights for the sake of knowledge sharing.
U can call the SP in vb using Command object and then passing parameters which u want to insert in table. U can directly execute sp using connection object in VB. When SP dont return any rows its good to execute it with connection object else with command object
Private Sub RunRestoreSP(buffer As String) Dim aCmdI As New adodb.Command Dim RecArr(5) ' parameters aCmdI.ActiveConnection = connConfig ' Connection object aCmdI.CommandTimeout = 10 aCmdI.CommandType = adCmdStoredProc aCmdI.CommandText = "addNewRow" ' SP Name RecArr(0) = Trim(buffer) RecArr(1) = txtSource.Text & "" & Trim(buffer) & ".bak" RecArr(2) = Trim(buffer) & "_Data" RecArr(3) = strSqlPath & Trim(buffer) & "_Data.mdf" RecArr(4) = Trim(buffer) & "_Log" RecArr(3) = strSqlPath & Trim(buffer) & "_Log.ldf" aCmdI.Execute , RecArr, adCmdStoredProc End Sub
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by dineshasanka</i><br /><br />Private Sub RunRestoreSP(buffer As String)<br />Dim aCmdI As New adodb.Command<br /> Dim RecArr(5) ' parameters<br /> aCmdI.ActiveConnection = connConfig ' Connection object<br /> aCmdI.CommandTimeout = 10<br /> aCmdI.CommandType = adCmdStoredProc <br /> aCmdI.CommandText = "addNewRow" ' SP Name<br /> RecArr(0) = Trim(buffer)<br /> RecArr(1) = txtSource.Text & "" & Trim(buffer) & ".bak"<br /> RecArr(2) = Trim(buffer) & "_Data"<br /> RecArr(3) = strSqlPath & Trim(buffer) & "_Data.mdf"<br /> RecArr(4) = Trim(buffer) & "_Log"<br /> RecArr(3) = strSqlPath & Trim(buffer) & "_Log.ldf"<br /> aCmdI.Execute , RecArr, adCmdStoredProc<br />End Sub<br /><hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote"><br /><br />Hi dinesh, u have given good eg. but ive seen optimising VB code for speed can be achieved more faster when using trim$() instead of Trim. try it out[<img src='/community/emoticons/emotion-1.gif' alt='' />]
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by ranjitjain</i><br /><br /><blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by dineshasanka</i><br /><br />Private Sub RunRestoreSP(buffer As String)<br />Dim aCmdI As New adodb.Command<br /> Dim RecArr(5) ' parameters<br /> aCmdI.ActiveConnection = connConfig ' Connection object<br /> aCmdI.CommandTimeout = 10<br /> aCmdI.CommandType = adCmdStoredProc <br /> aCmdI.CommandText = "addNewRow" ' SP Name<br /> RecArr(0) = Trim(buffer)<br /> RecArr(1) = txtSource.Text & "" & Trim(buffer) & ".bak"<br /> RecArr(2) = Trim(buffer) & "_Data"<br /> RecArr(3) = strSqlPath & Trim(buffer) & "_Data.mdf"<br /> RecArr(4) = Trim(buffer) & "_Log"<br /> RecArr(3) = strSqlPath & Trim(buffer) & "_Log.ldf"<br /> aCmdI.Execute , RecArr, adCmdStoredProc<br />End Sub<br /><hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote"><br /><br />Hi dinesh, u have given good eg. but ive seen optimising VB code for speed can be achieved more faster when using trim$() instead of Trim. try it out[<img src='/community/emoticons/emotion-1.gif' alt='' />]<br /><hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote"><br /><br />Thankx for the infomation. I am hardly using VB anyway [<img src='/community/emoticons/emotion-1.gif' alt='' />]