borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Enter Data into a table)Next Topic (printing in differents printers from VB) New Topic New Poll Post Reply
AndreaVB Forum : Printing : Flexgrid and ADODC
Poster Message
RonikaA
Level: Guest


icon Flexgrid and ADODC

Hi Looks like I can get some help here!Does anyone know how I can connect ADODC to a Flexgrid? I\'m new to vb and I\'d really appreciate any help!!The adodc is connected to a db in server2000.

17-05-2004 at 01:37 AM
| Quote Reply
BRMC
Level: VB Lord


Registered: 28-11-2003
Posts: 210
icon Re: Flexgrid and ADODC


Set YourFlexGrid.DataSource=YourAdodc


Bye

____________________________
I don't mind not going to heaven
As long as they've got cigarettes
in hell

17-05-2004 at 08:33 AM
View Profile Send Email to User Show All Posts | Quote Reply
RonikaA
Level: Guest

icon Re: Flexgrid and ADODC

Do you have a sample coding for it?

18-05-2004 at 05:39 AM
| Quote Reply
RonikaA
Level: Guest

icon Re: Flexgrid and ADODC

How do I set the titles of the grid and and assign each column in the table of the ADODC to each row and column of the grid?Thanks for replying earlier!!

18-05-2004 at 05:42 AM
| Quote Reply
BRMC
Level: VB Lord


Registered: 28-11-2003
Posts: 210
icon Re: Flexgrid and ADODC

Here's an example:


Dim strSQL as String
Dim strConnection as String

strConnection="Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=c:\somepath\mydb.mdb;" & _
           "Jet OLEDB:System Database=MySystem.mdw", _
           "myUsername", "myPassword"

Form.adodc.ConnectionString = strConnection
    
strSQL = "SELECT ID,Field1,Field2"
strSQL = strSQL & " FROM Table"
    
Form.adodc.RecordSource = strSQL
    
Set Form.Grid1.DataSource = Form.adodc



now in your table u have columns(0)=ID,columns(1)=Filed1,columns(2)=filed2

use in your form one datagrid.

then for the title:




With Grid1

    .Columns(0).Visible = False
    .Columns(1).Caption = "FIELD1"
    .Columns(1).Locked = True
    .Columns(1).AllowSizing = True
    .Columns(1).Width = 1000
    .Columns(2).Caption = "FIELD2"
    .Columns(2).Locked = True
    .Columns(2).AllowSizing = True
    .Columns(2).Width = 1000
  
End With



Hope this help.

Bye  

____________________________
I don't mind not going to heaven
As long as they've got cigarettes
in hell

18-05-2004 at 07:38 AM
View Profile Send Email to User Show All Posts | Quote Reply
RonikaA
Level: Guest

icon Re: Flexgrid and ADODC

Hey!
Everything looks good except my connection. My adodc in the form is connected to SQL2000. The connection string indicating is as follows:

Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Frontier;Data Source=RONIKA

When I replace this coding with ur connection coding it gives me an error. The first error highlights "1" aft SQLOLEDB? Do u have an alternative to find the connection string. Thank you sooo much for helping me out!!

I have attached my project in VB 6.0 so that u'll have an understanding of wut I'm trying to do here. I'm trying to add the flexgrid to purchase order tab.

Also I would really appreciate if you can main an example coding for example in the vendor form if the vendor no is selected in a combo box for the vendor name to appear in a text box. There's a separate adodc for vendor connected to the database.

19-05-2004 at 03:44 AM
| Quote Reply
BRMC
Level: VB Lord


Registered: 28-11-2003
Posts: 210
icon Re: Flexgrid and ADODC


OLE DB Provider for SQL Server


For Standard Security

oConn.Open "Provider=sqloledb;" & _
           "Data Source=myServerName;" & _
           "Initial Catalog=myDatabaseName;" & _
           "User Id=myUsername;" & _
           "Password=myPassword"

For a Trusted Connection

oConn.Open "Provider=sqloledb;" & _
           "Data Source=myServerName;" & _
           "Initial Catalog=myDatabaseName;" & _
           "Integrated Security=SSPI"

To connect to a "Named Instance"

oConn.Open "Provider=sqloledb;" & _
           "Data Source=myServerName\myInstanceName;" & _
           "Initial Catalog=myDatabaseName;" & _
           "User Id=myUsername;" & _
           "Password=myPassword"




Note: In order to connect to a SQL Server 2000 "named instance", you must have MDAC 2.6 (or greater) installed.


I don't understand your request.

quote:

Also I would really appreciate if you can main an example coding for example in the vendor form if the vendor no is selected in a combo box for the vendor name to appear in a text box. There's a separate adodc for vendor connected to the database.



what i understand is when u select a vendor in a combo box u want to display name in a text box , right?

but your combo is filled with a recordset or something else?

Bye  

____________________________
I don't mind not going to heaven
As long as they've got cigarettes
in hell
19-05-2004 at 10:51 AM
View Profile Send Email to User Show All Posts | Quote Reply
RonikaA
Level: Guest

icon Re: Flexgrid and ADODC

umm yea it was connected to the Purchase Order recordset(Combo)But if there's a alternative I'm glad to implement it

19-05-2004 at 03:01 PM
| Quote Reply
BRMC
Level: VB Lord


Registered: 28-11-2003
Posts: 210
icon Re: Flexgrid and ADODC

I work in this way:

to load a combobox


Public Sub LoadCombo()

Dim strSQL as String
Dim rsAdo1 as ADODB.RecordSet

    strSQL = "SELECT ID,Field FROM YourTable"
    
    Set rsAdo1 = New ADODB.Recordset
    rsAdo1.Open strSQL, yourConnection
    
    Combo.AddItem ""
    Combo.ItemData(Combo.NewIndex) = 0
        
    If rsAdo1.EOF = False Then
        Do While Not rsAdo1.EOF
        
            Combo.AddItem rsAdo1.Fields("Field")
            Combo.ItemData(Combo.NewIndex) = rsAdo1.Fields("ID")
        
            rsAdo1.MoveNext
            
        Loop
    End If
    
    Combo.ListIndex = 0
    
    Set rsAdo1 = Nothing
    
End Sub



where id is your primary key field

then when u click the combo:



Private Sub Combo_Click()

If Combo.ListIndex <> 0 Then
      Text1.Text= Combo.ItemData(Combo.ListIndex)
End If

End Sub



This is my way  

Bye  
BRMC

____________________________
I don't mind not going to heaven
As long as they've got cigarettes
in hell

19-05-2004 at 04:26 PM
View Profile Send Email to User Show All Posts | Quote Reply
RonikaA
Level: Guest

icon Re: Flexgrid and ADODC

Hi Again!

I have attached the coding that I've applied according to my database but I think the connection string is still messed up. I've attached 2 projects

1 Flex Grid
2. combo & text

hope I can I have the same connection string with both activated in the same form.


____________________________
Attached:
example.zip 4 KB (Downloads: 8)

20-05-2004 at 03:35 AM
| Quote Reply
BRMC
Level: VB Lord


Registered: 28-11-2003
Posts: 210
icon Re: Flexgrid and ADODC

Here your project revisited  

Try it and tell me.

It should work if your connection string is ok !



____________________________
I don't mind not going to heaven
As long as they've got cigarettes
in hell

____________________________
Attached:
example2.zip 4 KB (Downloads: 10)

20-05-2004 at 07:58 AM
View Profile Send Email to User Show All Posts | Quote Reply
RonikaA
Level: Guest

icon Re: Flexgrid and ADODC

Really cool !!!

The Grid works but the combo does not load the data to the menu in the combo.

To for my project to be alive I'll have to use your way of calling from the strConnection.

As I have the ADODC connected to the other tabs my project it doesnt not work in mine. So to change from ADODC connection to declaring the connection in the module and calling it in the form, how do I change the text boxes that I have in my form. For example, in customer , whats the coding to make the Customer Address appear in the text box using strConnection.

Basically what I'm asking is for the coding for Customer Address to appear in a text box using ConnectionString and ADODB.Connection in the module.

21-05-2004 at 02:30 AM
| Quote Reply
RonikaA
Level: Guest

icon Re: Flexgrid and ADODC

Hey!

Luckily I sent my project to you. Hope u havent deleted it. This is for one of my units from uni. After I tried the connection string in my program the interfaces got locked. Cud u mail back the coding I sent to u. I kept a back up of the database but not hte VB prog.

Thanks!!

21-05-2004 at 05:48 AM
| Quote Reply
BRMC
Level: VB Lord


Registered: 28-11-2003
Posts: 210
icon Re: Flexgrid and ADODC

Look in the LoadCombo , in SQL statement:

strSQLCombo = "SELECT C_No FROM Customer"

u have to when user select by combo , make another sql statement that take your customer address.

Sound like:


Private Sub Combo1_Click()
Dim rs as ADODB.RecordSet
dim str as String

If Me.Combo1.ListIndex <> 0 Then
     str="SELECT Address FROM Customer
     str=str & " WHERE C_No=" & Combo1.ItemData(Combo1.ListIndex) & ""

    set rs = New ADODB.RecordSet
    rs.Open str,cnAdo

    if rs.EOF=False Then
      Text1.Text=rs.Fields("Address").Value
    End If
  
    set rs=Nothing

End If

End Sub



the connection remane the same you have to open another recordset with another SQL statement.

Here's your old code.

Bye  

____________________________
I don't mind not going to heaven
As long as they've got cigarettes
in hell

____________________________
Attached:
example.zip 4 KB (Downloads: 6)

21-05-2004 at 07:43 AM
View Profile Send Email to User Show All Posts | Quote Reply
RonikaA
Level: Guest

icon Re: Flexgrid and ADODC

Thanks again I'll try that out. I mean the code of the Invoicing System with the 4 tabs(Customer, Accounts Payable. Receivable etc) in one form(frmFrontier_main) and Vendor. Hope u can find the project I'm talking about.(Frontier)

21-05-2004 at 02:58 PM
| Quote Reply
RonikaA
Level: Guest

icon Re: Flexgrid and ADODC

sorry about that I found the project I was refering to earlier. The combo does not load any data yet. Wonder y?Even when I run the example u sent the combo did not load any data.
This is the coding in the form

Private Sub Combo1_Click()
Dim rs As ADODB.Recordset
Dim str As String

If Me.Combo1.ListIndex <> 0 Then
     str = "SELECT V_No FROM Vendor"
     str = str & " WHERE V_No=" & Combo1.ItemData(Combo1.ListIndex) & ""

    Set rs = New ADODB.Recordset
    rs.Open str, cnAdo

    If rs.EOF = False Then
      Text1.Text = rs.Fields("V_No").Value
    End If
  
    Set rs = Nothing

End If

End Sub


This is the coding in the module

Global cnAdo As ADODB.Connection
Global strConnection As String

Public Sub Main()

strConnection = "Provider=SQLOLEDB.1;" & _
"Integrated Security=SSPI;" & _
"Persist Security Info=False;" & _
"Initial Catalog=Frontier;" & _
"Data Source=RONIKA"


Set cnAdo = New ADODB.Connection
cnAdo.ConnectionString = strConnection

cnAdo.Open

frmvendor.Show

End Sub

The connection is working as in the grid the data appears in the column.

22-05-2004 at 03:02 PM
| Quote Reply
RonikaA
Level: Guest

icon Re: Flexgrid and ADODC

Hi Again!
on top of the combo question I posted last I have another question. Hope u can help me out. I had to take the adodc out in all the tabs in my project coz I cudnt add a data environment to print reports with a adodc. I'm able to print reports but I'm unable to add records with this code.

deFrontier is the Data environment. rs is the Connection. Earlier it used to be the table name.recordset.addNew. I tried replacing it with the data Environment name.connection.addnew but it doesnt seem to be working. Do you have any other alternatives

Private Sub cmdC_Add_Click()
txtC_No.Enabled = True
txtC_Name.Enabled = True
txtComp_Name.Enabled = True
txttypeBiz.Enabled = True
deFrontier.rsCustomers.AddNewEnd Sub

24-05-2004 at 01:35 AM
| Quote Reply
BRMC
Level: VB Lord


Registered: 28-11-2003
Posts: 210
icon Re: Flexgrid and ADODC

Hi,

for adding new record i use INSERT INTO in sql like:



Private Sub cmdC_Add_Click()
Dim rs1 as ADODB.RecordSet
Dim strSQL as String

strSQL="INSERT INTO YourTable(Field1,Field2)
strSQL=strSQL & " VALUES(" & txtC_Name.Text & ""
strSQL=strSQL & ",'" & txtComp_Name.Text & "')"

set rs1=New ADODB.RecordSet
rs1.Open strSQL,yourconnection

set rs1=Nothing

End Sub



Bye

____________________________
I don't mind not going to heaven
As long as they've got cigarettes
in hell

24-05-2004 at 07:28 AM
View Profile Send Email to User Show All Posts | Quote Reply
RonikaA
Level: Guest

icon Re: Flexgrid and ADODC

hi

Thanks for ur reply.I appreciate it!I'll try that..Umm how should I use sql to rfresh and del? Hope u saw the question I posted on combo question. I have pasted it here any way!

The combo does not load any data yet. Wonder y?Even when I run the example u sent the combo did not load any data.
This is the coding in the form

Private Sub Combo1_Click()
Dim rs As ADODB.Recordset
Dim str As String

If Me.Combo1.ListIndex <> 0 Then
     str = "SELECT V_No FROM Vendor"
     str = str & " WHERE V_No=" & Combo1.ItemData(Combo1.ListIndex) & ""

    Set rs = New ADODB.Recordset
    rs.Open str, cnAdo

    If rs.EOF = False Then
      Text1.Text = rs.Fields("V_No").Value
    End If
  
    Set rs = Nothing

End If

End Sub


This is the coding in the module

Global cnAdo As ADODB.Connection
Global strConnection As String

Public Sub Main()

strConnection = "Provider=SQLOLEDB.1;" & _
"Integrated Security=SSPI;" & _
"Persist Security Info=False;" & _
"Initial Catalog=Frontier;" & _
"Data Source=RONIKA"


Set cnAdo = New ADODB.Connection
cnAdo.ConnectionString = strConnection

cnAdo.Open

frmvendor.Show

End Sub

The connection is working as in the grid the data appears in the column

24-05-2004 at 02:48 PM
| Quote Reply
BRMC
Level: VB Lord


Registered: 28-11-2003
Posts: 210
icon Re: Flexgrid and ADODC

Yes but the problem maybe occours when u load combo


Public Sub LoadCombo()

Dim strSQLCombo As String
Dim rsAdo As ADODB.Recordset
    
    strSQLCombo = "SELECT C_No FROM Customer"
    
    Set rsAdo = New ADODB.Recordset
    rsAdo.Open strSQLCombo, cnAdo
    
    Combo1.AddItem ""
    Combo1.ItemData(Combo1.NewIndex) = 0
        
    If rsAdo.EOF = False Then
        Do While Not rsAdo.EOF
        
            Combo1.AddItem (rsAdo.Fields("C_No"))
            Combo1.ItemData(Combo1.NewIndex) = rsAdo.Fields("C_No")
        
            rsAdo.MoveNext
            
        Loop
    End If
    
    Combo1.ListIndex = 0
    
    Set rsAdo = Nothing

End Sub




look at the sql statement maybe u put C_no and not V_no

Bye  

____________________________
I don't mind not going to heaven
As long as they've got cigarettes
in hell

24-05-2004 at 03:24 PM
View Profile Send Email to User Show All Posts | Quote Reply
RonikaA
Level: Guest

icon Re: Flexgrid and ADODC

Umm how should I use sql to rfresh and del as the adding coding?

25-05-2004 at 01:19 AM
| Quote Reply
RonikaA
Level: Guest

icon Re: Flexgrid and ADODC

This is the code in the module

Global rsAdo As ADODB.Connection
Global strConnection As String

Public Sub Main()

strConnection = "Provider=SQLOLEDB.1;" & _
"Integrated Security=SSPI;" & _
"Persist Security Info=False;" & _
"Initial Catalog=Frontier;" & _
"Data Source=RONIKA"


Set rsAdo = New ADODB.Connection
rsAdo.ConnectionString = strConnection

rsAdo.Open

'Form1.Show

End Sub

And this is in the form.

Private Sub Combo1_Click()
Dim rs As ADODB.Recordset
Dim str As String

If Me.Combo1.ListIndex <> 0 Then
     str = "SELECT C_Name FROM Customer"
     str = str & " WHERE C_No=" & Combo1.ItemData(Combo1.ListIndex) & ""

    Set rs = New ADODB.Recordset
    rs.Open str, rsAdo

    If rs.EOF = False Then
      txtC_Name.Text = rs.Fields("C_Name").Value
    End If
  
    Set rs = Nothing

End If

End Sub

I have attached the prog just in case. Hope u will be able to send the coding  for refresh and del in SQL

____________________________
Attached:
Final.zip 63 KB (Downloads: 12)

25-05-2004 at 04:39 AM
| Quote Reply
RonikaA
Level: Guest

icon Re: Flexgrid and ADODC

I have attached the wrong project. Herewith is attached the correct one!Still the combo does not show any data. The combo should show data at load and select the data to the text at click?

____________________________
Attached:
example2.zip 40 KB (Downloads: 13)

25-05-2004 at 04:49 AM
| Quote Reply
BRMC
Level: VB Lord


Registered: 28-11-2003
Posts: 210
icon Re: Flexgrid and ADODC

mmm i see u attached directly a datasource to your combo , so i don't know wich field the combo load itself ,and his index , so :



     str = "SELECT V_No FROM Vendor"
     str = str & " WHERE V_No=" & Combo1.ItemData(Combo1.ListIndex) & ""



try with Combo1.ListIndex or Combo1.Text.

But if the combo don't show any data i think the problem is with the datasource , vendor is another table or another DB?



____________________________
I don't mind not going to heaven
As long as they've got cigarettes
in hell

25-05-2004 at 07:31 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : Printing : Flexgrid and ADODC
Previous Topic (Enter Data into a table)Next Topic (printing in differents printers from VB) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2009 Andrea Tincaniborder