By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,062 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

v.b 6.0 connection with adodc through sqlserver not working

P: 31
Hi all,

I,m new to vb.6.0 and i don,t know how to connect to sql server through v.b 6.0 with the help of adodc control, and anyone plz tell me how connect and insert ,update,delete and other functions, coz i tried in m.s access not in sqlserver,

This is the coding which i used in ms.access
Expand|Select|Wrap|Line Numbers
  1. 'for insert
  2. rs.Fields(0) = Text1.Text
  3. rs.Fields(1) = Text2.Text
  4. rs.AddNew
  5. rs.Update
  6.  
  7. for update
  8.  
  9. rs.Fields(0) = Text1.Text
  10. rs.Fields(1) = Text2.Text
  11. rs.Update
  12. MsgBox "You suceesfully inserted the value"
  13. adodc1.Refresh
  14. Grid1.Refresh
  15.  
  16. for select
  17. Dim con As ADODB.Connection
  18. Dim rs As ADODB.Recordset
  19. Dim strconnect As String
  20. Set con = New ADODB.Connection
  21. Set rs = New ADODB.Recordset
  22. strconnect = "Driver={SQL Server};Server=FOCUSSERVER;Database=Northwind;Uid=sa;"
  23. con.Open strconnect
  24. rs.Open "select * from Sales", con, adOpenDynamic, adLockOptimistic
  25. MsgBox "Connected Suceesfully"
  26.  
  27. 'for delete
  28. rs.Delete
  29. MsgBox "You suceesfully deleted the record"
  30. rs.MoveFirst
  31. Adodc1.Refresh
  32.  
can anyone plz tell me what changes should i do in above codings or send me some sample coding plz urgent
Apr 3 '08 #1
Share this Question
Share on Google+
6 Replies


QVeen72
Expert 100+
P: 1,445
Hi,

You are trying to Connect through ADODC or using ADO Objects...?

Is your Conn Object Opened properly...?

Regards
Veena
Apr 3 '08 #2

P: 31
yeah i,m trying with adodc control but there is no connection in datagrid if i right click the adodc control and specify the following details
1datasource
2databasename
3tablename
then the records fetch in the table but if i,m trying trough coding it was not working and also tell me about the insert,update,delete codings
plzzzzzzzzzzzzzzzzzzzzzzzzz
Apr 3 '08 #3

QVeen72
Expert 100+
P: 1,445
Hi,

Add a New ADODC to your Form, and Give this in property "ConnectionString"

Provider=SQLOLEDB.1;Password=MyPassword;Persist Security Info=True;User ID=MyLoginName;Initial Catalog=MYDBNAME;Data Source=MyServerName

First Create a "Public" user in SQL Server.. Give Permissions To this User.
Change Connection String Accordingly..

and In "RecordSource" property: Click on "..."
and Give:
CommandType = 1 - cmdText
Command Text = "Select * From Myable

and Give DataGrid's datasource = this adodc1.

Regards
Veena
Apr 3 '08 #4

P: 31
Thank you veena , i,v done the all above things what u mentioned but i need a clarity about the insert,update.delete commands while we r using adodc dontrol
Thanks in advance
Apr 3 '08 #5

QVeen72
Expert 100+
P: 1,445
Hi,

Expand|Select|Wrap|Line Numbers
  1. 'Add Code
  2. Adodc1.Recordset.AddNew
  3. Adodc1.Recordset.Fields(0) = Text1.Text
  4. Adodc1.Recordset.Fields(1) = Text2.Text
  5. Adodc1.Recordset.Update
  6.  
  7. 'Edit Code
  8. ' Move to the Record and 
  9. Adodc1.Recordset.Fields(0) = Text1.Text
  10. Adodc1.Recordset.Fields(1) = Text2.Text
  11. Adodc1.Recordset.Update
  12.  
  13. 'Delete Code
  14. 'Move to the Record
  15. Adodc1.Recordset.Delete
  16.  
  17. ' To Move /Search To a Particular Field, (Usually PK of the Table)
  18.  
  19. Adodc1.Recordset.MoveFirst
  20. Adodc1.Recordset.Find "MyFieldName='" & Text1.Text & "'"
  21. If Adodc1.Recordset.EOF Then
  22.     MsgBox "Search Not Found"
  23. Else
  24.     'Code To Populate / Edit / Delete
  25. End If
  26.  
  27.  
After Update (for all above Data Operations) it is better to Refresh the Datacontrol.

I hope its Clear

Regards
Veena
Apr 3 '08 #6

P: 31
Thank you veena for spending on me some time
Apr 3 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.