0

Dear friend ,iam working on a project in which i have to make a database on 14 columns and then a program in vb to add the new data,delet and find. i have created database and a flexgrid in vb.but the problem is that icant be able to connect the data base with flexgrid.

i request you to please guide me how can i connect the database with flexgrid in the form.and how to code add ,delet and find buttons.

3
Contributors
4
Replies
11
Views
6 Years
Discussion Span
Last Post by AndreRet
0

what are you used to connect? adodb?oledb?adodc control?
also post your code..show some effort first..how far u doing this..

0

iam want to connect with ADODC,database name is db1.mdb
This is a code of that form .

Private Sub CmdAddEntry_Click()
  'add a new entry to our table.
    With Data1.Recordset
        .AddNew
        !KhataNumber = txtKhataNumber
        !SellerName = txtSellerName
        !TruckNumber = txtTruckNumber
        !Quantity = txtQuantity
        !Gross = txtGross
        !Commision = txtCommision
        !Rent = txtRent
        !Labour = txtLabour
        !ReturnExpense = txtReturnExpense
        !ChamanKharcha = txtChamanKharcha
        !StoreExpense = txtStoreExpense
        !DakPhone = txtDakPhone
        !Manisha = txtManisha
        !TotalExpense = txtTotalExpense
        !Net = txtNet
        .Update
        .Requery
    End With
    Data1.Refresh

    'clear the text fields once the new record is added
   txtKhataNumber = ""
    txtSellerName = ""
    txtTruckNumber = ""
     txtQuantity = ""
      txtGross = ""
       txtCommision = ""
        txtRent = ""
         txtLabour = ""
          txtReturnExpense = ""
           txtChamanKharcha = ""
            txtStoreExpense = ""
             txtDakPhone = ""
              txtManisha = ""
               txtTotalExpense = ""
                txtNet = ""
                 
                 
            
    

End Sub

Private Sub cmdRemoveEntry_Click()
'delete an entry from the database
    With Data1.Recordset
        .Move (MSFlexGrid1.Row - 1) ' we minus one because row zero is the header row
        .Delete
    End With
    Data1.Refresh
    
    'set the focus back to the first add field
    txtKhataNumber.SetFocus

End Sub

Private Sub Form_Load()
'the format string just lets you define a format for how
    'your flexgrid will appear
    MSFlexGrid1.FormatString = "KhataNumber         |" & _
        "SellerName                                 | Net"
    
    'make sure the search path to the db is always in the right spot
    Data1.DatabaseName = App.Path & "\db1.mdb"
    
    'set up the recordsource for the datasource and flexgrid control
    'in this case, it's just a raw SQL query, simple simple.
    Data1.RecordSource = "select * from db1 order by KhataNumber"

End Sub

Private Sub txtDakPhone_Change()

End Sub

Private Sub txtGross_Change()

End Sub

Private Sub txtLabour_Change()

End Sub

Private Sub txtManisha_Change()

End Sub

Private Sub txtSellerName_Change()

End Sub

Private Sub txtTotalExpense_Change()

End Sub

Private Sub txtTruckNumber_Change()

End Sub

Edited by satti: n/a

0

here is an update,ihave corrected the database path now when i try to run this form it gives me an error ,*invalid outside procedure*.
here is a code..

À

Private Sub CmdAddEntry_Click()
  'add a new entry to our table.
    With Data1.Recordset
        .AddNew
        !KhataNumber = txtKhataNumber
        !SellerName = txtSellerName
        !TruckNumber = txtTruckNumber
        !Quantity = txtQuantity
        !Gross = txtGross
        !Commision = txtCommision
        !Rent = txtRent
        !Labour = txtLabour
        !ReturnExpense = txtReturnExpense
        !ChamanKharcha = txtChamanKharcha
        !StoreExpense = txtStoreExpense
        !DakPhone = txtDakPhone
        !Manisha = txtManisha
        !TotalExpense = txtTotalExpense
        !Net = txtNet
        .Update
        .Requery
    End With
    Data1.Refresh

    'clear the text fields once the new record is added
   txtKhataNumber = ""
    txtSellerName = ""
    txtTruckNumber = ""
     txtQuantity = ""
      txtGross = ""
       txtCommision = ""
        txtRent = ""
         txtLabour = ""
          txtReturnExpense = ""
           txtChamanKharcha = ""
            txtStoreExpense = ""
             txtDakPhone = ""
              txtManisha = ""
               txtTotalExpense = ""
                txtNet = ""
                 
                 
            
    

End Sub

Private Sub cmdRemoveEntry_Click()
'delete an entry from the database
    With Data1.Recordset
        .Move (MSFlexGrid1.Row - 1) ' we minus one because row zero is the header row
        .Delete
    End With
    Data1.Refresh
    
    'set the focus back to the first add field
    txtKhataNumber.SetFocus

End Sub

Private Sub Form_Load()
'the format string just lets you define a format for how
    'your flexgrid will appear
    MSFlexGrid1.FormatString = "KhataNumber         |" & _
        "SellerName                                 | Net"
    
    'make sure the search path to the db is always in the right spot
    Data1.DatabaseName = App.Path & "\db1.mdb"
    
    'set up the recordsource for the datasource and flexgrid control
    'in this case, it's just a raw SQL query, simple simple.
    Data1.RecordSource = "select * from DailyExpense order by KhataNumber"

End Sub
0

Try thye following to load data into the msflexgrid control -

Set MSFlexGrid1.Datasource = Data1.Recordsource
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.