|
Hi Everybody!
I am using VB6.0 & SQL Server 7.0
Following is my database Connection code
Dim db As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sql As String
Set db = New ADODB.Connection
db.Provider = "SQLOLEDB"
db.ConnectionString = "server=SUNANDA;uid=sa;pwd=ranjita1;database=crm"
db.Open
Set rs = New ADODB.Recordset
sql = "Select * from AccountHead"
Set rs.ActiveConnection = db
rs.CursorLocation = adUseClient
rs.CursorType = adOpenStatic
rs.LockType = adLockOptimistic
rs.Open sql, , , , adCmdText
I have placed navigation buttons on my form, but the Next & Previous buttons are not working properly.
When I first time clicks the Next button , the recordset goes to the next record but when I click it second time, the record doesn’t get changed.
When I press the previous button, the recordset points to the first record, instead of pointing to the previous record.
Here is my code for navigational buttons :
Public Sub MoveFields()
txtAcId.Text = rs("AcHeadID")
txtAcName.Text = rs("AcHeadName")
txtAcMobile.Text = rs("Mobile")
txtAcEmail.Text = rs("EmailID")
End Sub
Private Sub cmdFirst_Click()
rs.MoveFirst
MoveFields
cmdPrev.Enabled = False
cmdNext.Enabled = True
End Sub
Private Sub cmdLast_Click()
rs.MoveLast
MoveFields
cmdNext.Enabled = False
cmdPrev.Enabled = True
End Sub
Private Sub cmdNext_Click()
rs.MoveNext
If rs.EOF Then
rs.MoveLast
cmdNext.Enabled = False
End If
MoveFields
cmdPrev.Enabled = True
End Sub
Private Sub cmdRemove_Click()
rs.Delete
rs.MoveNext
If rs.EOF Then
rs.MoveLast
End If
End Sub
Private Sub cmdPrev_Click()
rs.MovePrevious
If rs.BOF Then
rs.MoveFirst
cmdPrev.Enabled = False
End If
MoveFields
cmdNext.Enabled = True
End Sub
Pls. tell me, where I am wrong.
Thanks
|
|
|
|
|
Hi
Dear Please first check where you write the code for recordset and connection.
Then try following code for your record movement
Next record
if not rs.eof then
rs.movenext()
....
end if
previous record
if not rs.bof then
rs.moveprevious()
.....
end if
If the problem is there then please post new message with you complete form code so I can sort your issue.
Regards
Tushar kothari
|
|
|
|
|
I have written the code for recordset and connection in sub main()
I am calling the procedure in each click event.
|
|
|
|
|
Hi,
I am using ASp.NET 1.1
Now when I call a stored procedure from code behind file and the stored procedure raises an error how to catch this error in code behind file
Thanks and Regards,
Uma
|
|
|
|
|
Hi
you can catch exception by following
Catch ex As SqlClient.SqlException
Tushar kothari
|
|
|
|
|
You can use output paramter, return value or as mentioned SQlexception. I prefer return value as this help me to use customize message from resource file,
|
|
|
|
|
:(Hi Everybody!
I am using VB6.0 & SQL Server 7.0
Following is my database Connection code
Dim db As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sql As String
Set db = New ADODB.Connection
db.Provider = "SQLOLEDB"
db.ConnectionString = "server=SUNANDA;uid=sa;pwd=ranjita1;database=crm"
db.Open
Set rs = New ADODB.Recordset
sql = "Select * from AccountHead"
Set rs.ActiveConnection = db
rs.CursorLocation = adUseClient
rs.CursorType = adOpenStatic
rs.LockType = adLockOptimistic
rs.Open sql, , , , adCmdText
I have placed buttons on the form to Add, Delete, Edit and Update the records of the table. But in the click event of the Update button, the recordset is not supporting the Edit method. The only method it is showing in (VBA) the dropdown list is EditMode.
How will I then Edit the records?
Pls. help me out.
Thankyou.
|
|
|
|
|
Hi
Dear please concentrate on your following code
rs.CursorType = adOpenStatic
As you had open the cursor in Static mode there is no edit permission for this record set.
You gave to open the recordset in non static mode.
Regards
Tushar kothari
|
|
|
|
|
Hi! Tushar
I have tried with
rs.CursorType=adOpenDynamic
But of no use.
Pls. suggest.
regards
ranjita
|
|
|
|
|
Hi
If you want just to update the record in recordset then you have to set the fileds values of rs then call rs.update
If this method is not wirking the please relpy back then I will try some odd solution for you.
Regards
Tushar kothari
|
|
|
|
|
I wants to edit the existing record and then update.
what u r suggesting that i am using in the click event of my save button.
regards
ranjita
|
|
|
|
|
Hi
This is the tested code so please use it
Private Sub Form_Load()
Dim db As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sql As String
Set db = New ADODB.Connection
db.Provider = "SQLOLEDB"
db.ConnectionString = "Provider=SQLOLEDB.1;Password=thk;Persist Security Info=True;User ID=thk;Initial Catalog=Dhanavantari;Data Source=TUSHAR"
db.Open
Set rs = New ADODB.Recordset
sql = "Select * from WardMaster"
Set rs.ActiveConnection = db
rs.CursorLocation = adUseServer
rs.CursorType = adOpenDynamic
rs.LockType = adLockPessimistic
rs.Open sql, , , , adCmdText
End Sub
on Save client button
rs.Fields(1) = trim(txtwardname.text)
rs.Fields(2) = val(txtrate.text)
rs.Update
So now you can edit the recordset and then update it
ADO is the connected type of recordset so you can update one record at a time.
If you have some other problem which i had not understand the please brief it
regards
Tushar kothari
|
|
|
|
|
i am working in vb.net2.0 version.
can u help me with code that how can i populate the datagridview in edit mode which will open in another form when one selects the row of a datagridview.
regards
Taniya Banerjee
|
|
|
|
|
Hi,
I have a stored procedure with 1 parameter.
The value that I pass to the parameter is a select statement.
The question is how do I execute this select statement that is passed as parameter that returns the rows?
Thanks and Regards,
Uma
|
|
|
|
|
Hi,
You can use sp_executesql to execute the sqlquery which is in a variable.
Best Regards,
Apurva Kaushal
|
|
|
|
|
CReate proc test (@sName Char(4))
AS
BEGIN
SELECT col1 from table where name=@sname
end
To execute this
EXEC Test 'Amit'
Amit
|
|
|
|
|
Hi,
probably the question was that there is a sql statement which is there in the variable and how to execute that. Thats why I have given that solution. To execute a stored procedure is the same what you have given.
Best Regards,
Apurva Kaushal
|
|
|
|
|
Say the user has a copy of her database (let’s call it MyData.mdb) on her PC. There is also a copy of that database on a central server website. Now what I want to do is have the user edit that database on her PC and then hit a “Synch” button, which will connect to the web server, updating the database there. I don’t want to have to re-upload the entire MyData.mdb every time What’s some industry methods for doing this? Can someone point me to a good article or tutorial? Thanks.
|
|
|
|
|
Use DTS and in SQL 2005 you have the flexbility to check whether this is new or updated record. We have done similar sort of operation for one of our project. but please note that is for xsl file to SQL server.
Amit
|
|
|
|
|
Send me some tips for ledger entries. Any one who had worked in ledgers, tell me that whether all voucher's data is sent to ledger? And all about ledgers?
thanks
Syed Shahid Hussain
|
|
|
|
|
Q. In SP's if one has to use some if...else condition with multiple sentances then how to use them....
Parag
|
|
|
|
|
I am not sure what you mean by "multiple sentances", but in sql server:
IF @value = 1
BEGIN
do something
END
ELSE
BEGIN
do something else
END
END IF
Mike Lasseter
|
|
|
|
|
SQL Server 2005 Books Online
IF...ELSE (Transact-SQL) [^]
--EricDV Sig---------
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them.
- Laurence J. Peters
|
|
|
|
|
hello,
can anybuddy plz tell me how we can use SQL Server 2000 on Windows XP pro. I'm working on a project that requires replication as well. For the moment, I'm working on Win 2000 Server and using Sql server 2000 enterprise ed. but I want to work on WinXP rather. So can u plz give me some solution to it. can we use Sqlserver 2000 professional edition or whatever on xp that also gives replication features.
Rocky
|
|
|
|
|
The Standard and Enterprise Editions will only install on Server-class operating systems (Windows 2000 Server, Advanced Server, Datacenter Server; Windows Server 2003 Standard Edition, Enterprise Edition, Datacenter Edition). On Windows XP the only production versions permitted are Workgroup Edition or Desktop Engine (MSDE).
MSDE can act as a replication subscriber but not as a publisher.
If all you're doing is testing out changes as a developer, it's fine to use the Developer Edition.
See SQL Server 2000 System Requirements[^] at microsoft.com.
|
|
|
|