whats wrong in this code snippet? 
Author Message
 whats wrong in this code snippet?

'select file to link

Dim openFileDialog1 As New OpenFileDialog()
Dim filepath As String
openFileDialog1.InitialDirectory = "c:\"
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = True
If openFileDialog1.ShowDialog() = DialogResult.OK Then
    filepath = "File://" & openFileDialog1.FileName
    'Me.BindingContext(DataViewCompany, "Documents").AddNew()
    Me.DataGrid2.Controls.Item("url").Text = filepath
End If

Datagrid 2 is on a winform and has a bound field URL, I am trying to put the result of Filepath into the current row,but would like to place it in a new record if possible? as it is now it produces an error trying to cast url into a value!

Colin



Thu, 02 Sep 2004 04:22:50 GMT  
 whats wrong in this code snippet?

Hi Colin,
    I always use a DataSet to update my datagrid.  If you want to add a new row you would do something like follows:

    Dim dr as DataRow
    dr = yourdataset.Tables(0).NewRow
    dr.Item("url") = filepath
    yourdataset.Tables(0).Rows.Add(dr)
    yourdataset.AcceptChanges()
    yourdatagrid.SetDataBinding(yourdataset, "tablename")

    Be sure to fill in the correct names for 'yourdataset', 'yourdatagrid', and 'tablename'.
    When you want to update instead of add you simply update the row in the dataset.  Hope this helps.  Ken.
  'select file to link

  Dim openFileDialog1 As New OpenFileDialog()
  Dim filepath As String
  openFileDialog1.InitialDirectory = "c:\"
  openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
  openFileDialog1.FilterIndex = 2
  openFileDialog1.RestoreDirectory = True
  If openFileDialog1.ShowDialog() = DialogResult.OK Then
      filepath = "File://" & openFileDialog1.FileName
      'Me.BindingContext(DataViewCompany, "Documents").AddNew()
      Me.DataGrid2.Controls.Item("url").Text = filepath
  End If

  Datagrid 2 is on a winform and has a bound field URL, I am trying to put the result of Filepath into the current row,but would like to place it in a new record if possible? as it is now it produces an error trying to cast url into a value!

  Colin



Thu, 02 Sep 2004 14:08:31 GMT  
 whats wrong in this code snippet?

thanks for code, using a datarow makes sense.

Colin


  Hi Colin,
      I always use a DataSet to update my datagrid.  If you want to add a new row you would do something like follows:

      Dim dr as DataRow
      dr = yourdataset.Tables(0).NewRow
      dr.Item("url") = filepath
      yourdataset.Tables(0).Rows.Add(dr)
      yourdataset.AcceptChanges()
      yourdatagrid.SetDataBinding(yourdataset, "tablename")

      Be sure to fill in the correct names for 'yourdataset', 'yourdatagrid', and 'tablename'.
      When you want to update instead of add you simply update the row in the dataset.  Hope this helps.  Ken.

    'select file to link

    Dim openFileDialog1 As New OpenFileDialog()
    Dim filepath As String
    openFileDialog1.InitialDirectory = "c:\"
    openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
    openFileDialog1.FilterIndex = 2
    openFileDialog1.RestoreDirectory = True
    If openFileDialog1.ShowDialog() = DialogResult.OK Then
        filepath = "File://" & openFileDialog1.FileName
        'Me.BindingContext(DataViewCompany, "Documents").AddNew()
        Me.DataGrid2.Controls.Item("url").Text = filepath
    End If

    Datagrid 2 is on a winform and has a bound field URL, I am trying to put the result of Filepath into the current row,but would like to place it in a new record if possible? as it is now it produces an error trying to cast url into a value!

    Colin



Thu, 02 Sep 2004 19:42:57 GMT  
 whats wrong in this code snippet?

Ken,

That seemed like a good idea until i tried to implement it. I have now hit a problem I have seen before in this group, my dataset is designed as follows

dscompany.tables(0) = company (Primary, companyID, Identity)
dsCompanyTables(1) = documents  (PrimaryKey,documentID,Identity)
relation CompanyDocuments (CompanyID)

When adding a document record I need to determine the ID Of the Company in the dataset, and even if I set this to a known value the Increment field in the document appears be set to a value of 1 and not the next available ID for a child record,  as this record already exists it errors.

If you add a record manually to the grid these values are populated correctly any idea how to accomplish this when coding a datarow

Colin
  thanks for code, using a datarow makes sense.

  Colin


    Hi Colin,
        I always use a DataSet to update my datagrid.  If you want to add a new row you would do something like follows:

        Dim dr as DataRow
        dr = yourdataset.Tables(0).NewRow
        dr.Item("url") = filepath
        yourdataset.Tables(0).Rows.Add(dr)
        yourdataset.AcceptChanges()
        yourdatagrid.SetDataBinding(yourdataset, "tablename")

        Be sure to fill in the correct names for 'yourdataset', 'yourdatagrid', and 'tablename'.
        When you want to update instead of add you simply update the row in the dataset.  Hope this helps.  Ken.

      'select file to link

      Dim openFileDialog1 As New OpenFileDialog()
      Dim filepath As String
      openFileDialog1.InitialDirectory = "c:\"
      openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
      openFileDialog1.FilterIndex = 2
      openFileDialog1.RestoreDirectory = True
      If openFileDialog1.ShowDialog() = DialogResult.OK Then
          filepath = "File://" & openFileDialog1.FileName
          'Me.BindingContext(DataViewCompany, "Documents").AddNew()
          Me.DataGrid2.Controls.Item("url").Text = filepath
      End If

      Datagrid 2 is on a winform and has a bound field URL, I am trying to put the result of Filepath into the current row,but would like to place it in a new record if possible? as it is now it produces an error trying to cast url into a value!

      Colin



Thu, 02 Sep 2004 20:25:26 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Whats wrong with withis code???

2. Whats Wrong with this CODE!

3. whats wrong with this code?

4. Whats wrong with this line of code?

5. Whats wrong with this code

6. Whats wrong with this code?

7. whats wrong with this code??????

8. Help: Whats wrong with following code??

9. Whats Wrong with this code????

10. Whats wrong with this code

11. Can someone explain whats wrong with this code?

12. whats wrong with this code??????

 

 
Powered by phpBB® Forum Software