v.b 6.0 connection with adodc through sqlserver not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hussainiyad
    New Member
    • Feb 2007
    • 31

    v.b 6.0 connection with adodc through sqlserver not working

    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
    [code=vb]
    'for insert
    rs.Fields(0) = Text1.Text
    rs.Fields(1) = Text2.Text
    rs.AddNew
    rs.Update

    for update

    rs.Fields(0) = Text1.Text
    rs.Fields(1) = Text2.Text
    rs.Update
    MsgBox "You suceesfully inserted the value"
    adodc1.Refresh
    Grid1.Refresh

    for select
    Dim con As ADODB.Connectio n
    Dim rs As ADODB.Recordset
    Dim strconnect As String
    Set con = New ADODB.Connectio n
    Set rs = New ADODB.Recordset
    strconnect = "Driver={SQ L Server};Server= FOCUSSERVER;Dat abase=Northwind ;Uid=sa;"
    con.Open strconnect
    rs.Open "select * from Sales", con, adOpenDynamic, adLockOptimisti c
    MsgBox "Connected Suceesfully"

    'for delete
    rs.Delete
    MsgBox "You suceesfully deleted the record"
    rs.MoveFirst
    Adodc1.Refresh
    [/code]
    can anyone plz tell me what changes should i do in above codings or send me some sample coding plz urgent
    Last edited by debasisdas; Apr 3 '08, 06:37 AM. Reason: added code=vb tags
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

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

    Is your Conn Object Opened properly...?

    Regards
    Veena

    Comment

    • hussainiyad
      New Member
      • Feb 2007
      • 31

      #3
      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,d elete codings
      plzzzzzzzzzzzzz zzzzzzzzzzzz

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

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

        Provider=SQLOLE DB.1;Password=M yPassword;Persi st Security Info=True;User ID=MyLoginName; Initial Catalog=MYDBNAM E;Data Source=MyServer Name

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

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

        and Give DataGrid's datasource = this adodc1.

        Regards
        Veena

        Comment

        • hussainiyad
          New Member
          • Feb 2007
          • 31

          #5
          Thank you veena , i,v done the all above things what u mentioned but i need a clarity about the insert,update.d elete commands while we r using adodc dontrol
          Thanks in advance

          Comment

          • QVeen72
            Recognized Expert Top Contributor
            • Oct 2006
            • 1445

            #6
            Hi,

            [code=vb]
            'Add Code
            Adodc1.Recordse t.AddNew
            Adodc1.Recordse t.Fields(0) = Text1.Text
            Adodc1.Recordse t.Fields(1) = Text2.Text
            Adodc1.Recordse t.Update

            'Edit Code
            ' Move to the Record and
            Adodc1.Recordse t.Fields(0) = Text1.Text
            Adodc1.Recordse t.Fields(1) = Text2.Text
            Adodc1.Recordse t.Update

            'Delete Code
            'Move to the Record
            Adodc1.Recordse t.Delete

            ' To Move /Search To a Particular Field, (Usually PK of the Table)

            Adodc1.Recordse t.MoveFirst
            Adodc1.Recordse t.Find "MyFieldNam e='" & Text1.Text & "'"
            If Adodc1.Recordse t.EOF Then
            MsgBox "Search Not Found"
            Else
            'Code To Populate / Edit / Delete
            End If

            [/code]

            After Update (for all above Data Operations) it is better to Refresh the Datacontrol.

            I hope its Clear

            Regards
            Veena

            Comment

            • hussainiyad
              New Member
              • Feb 2007
              • 31

              #7
              Thank you veena for spending on me some time

              Comment

              Working...