[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 450
  • Last Modified:

Updating the tables with C1TrueDBGrid for .Net 2.0

I have the simplest if applications binding a a table to a Component1 True DB Grid for .net

I have used the VB6 version for years, but I am getting nowhere with this.

Can anyone help?
0
grwallace
Asked:
grwallace
  • 4
  • 2
1 Solution
 
vb_jonasCommented:
Doesnt this work?

c1TrueDBGrid1.DataSource = MyDataSet.MyDataTable

0
 
vb_jonasCommented:
or MyDataSet.Tables("TableName")
0
 
vb_jonasCommented:
And the table should be filled with data ofcourse. MyDataAdapter.Fill(MyDataSet) for example.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
grwallaceAuthor Commented:
thanks for this _ can now populate the grid.

the next problem is getting it to update. If I am linked to a single table then I can create the update commands simply with the following function:-

 Public Function CreateCommands()
        Try
            MyAdapter = Nothing
            MyAdapter = New SqlClient.SqlDataAdapter(SelString, MyConn)
            cmdBuilder1 = New SqlCommandBuilder(MyAdapter)
            OleDBCommand1 = New SqlCommand(SelString, MyConn)
            MyAdapter.SelectCommand = OleDBCommand1
            MyAdapter.DeleteCommand = cmdBuilder1.GetDeleteCommand()
            MyAdapter.InsertCommand = cmdBuilder1.GetInsertCommand()
            MyAdapter.UpdateCommand = cmdBuilder1.GetUpdateCommand()
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try
    End Function

But if I have more than one table in the query then it doesn't work.

What I am looking for is something like:-

Table Products              Table Sales

ProdId                          SalesId
PartNumber                  ProdId
Description                   Quantity
                                   Price

To show on the grid:-

Part Number                 Description                  Quantity      Price
AMC
0
 
grwallaceAuthor Commented:
I made a mistake and posted before I was finished.

 
   
   
      Featured Expert  
nayernaguib  
Ask An Expert Now!  
 
   
   
 Top 15
Overall
   Programming  
 
 
  InteractiveMind  599052
 
  cookre  546064
 
  Idle_Mind  382247
 
  Raisor  294440
 
  jaime_olivares  274643
 
  AlexFM  243630
 
  Kavar  234568
 
  Arthur_Wood  232497
 
  pratap_r  216305
 
  nayernaguib  214262
 
  twalgrave  205843
 
  julianH  194199
 
  sunnycoder  186150
 
  emoreau  178755
 
  JesterToo  170309
Hall of Fame  
 
   
   
  What is your expert ranking?  
Topic Area

   
Certified Expert
Your Level
 
 
Get Certified Now  
Master  50,000
Guru  150,000
Wizard  300,000
Sage  500,000
Genius  1,000,000
 
 
   
   
 Top 15
Yearly
   Programming  
 
 
  InteractiveMind  207360
 
  Raisor  157969
 
  nayernaguib  133872
 
  Idle_Mind  104731
 
  nepostojeci_email  70390
 
  bruintje  50442
 
  liviutudor  49716
 
  cookre  49378
 
  JesterToo  43854
 
  MilanKM  39082
 
  bglodde  35694
 
  angelIII  35372
 
  AlexFM  34520
 
  gabeso  34349
 
  jhance  32812
Hall of Fame  
 
   
 Home All Topics Programming Viewing a Question


Search 1,591,186 Solutions      
Search Help   Restrict to this Topic Area   Advanced Search

 Title: Updating the tables with C1TrueDBGrid for .Net 2.0
asked by grwallace on 05/14/2006 05:21AM PDT  
This question is worth  500 Points  
 
 


I have the simplest if applications binding a a table to a Component1 True DB Grid for .net

I have used the VB6 version for years, but I am getting nowhere with this.

Can anyone help?
 
 Send to a Friend     Printer Friendly  
   
 Comment from vb_jonas
Date: 05/14/2006 10:04PM PDT
 Comment  


Doesnt this work?

c1TrueDBGrid1.DataSource = MyDataSet.MyDataTable


 
Comment from vb_jonas
Date: 05/14/2006 10:05PM PDT
 Comment  


or MyDataSet.Tables("TableName")
 
Comment from vb_jonas
Date: 05/14/2006 10:08PM PDT
 Comment  


And the table should be filled with data ofcourse. MyDataAdapter.Fill(MyDataSet) for example.
 
Comment from grwallace
Date: 05/18/2006 05:04AM PDT
 Your Comment  


thanks for this _ can now populate the grid.

the next problem is getting it to update. If I am linked to a single table then I can create the update commands simply with the following function:-

 Public Function CreateCommands()
        Try
            MyAdapter = Nothing
            MyAdapter = New SqlClient.SqlDataAdapter(SelString, MyConn)
            cmdBuilder1 = New SqlCommandBuilder(MyAdapter)
            OleDBCommand1 = New SqlCommand(SelString, MyConn)
            MyAdapter.SelectCommand = OleDBCommand1
            MyAdapter.DeleteCommand = cmdBuilder1.GetDeleteCommand()
            MyAdapter.InsertCommand = cmdBuilder1.GetInsertCommand()
            MyAdapter.UpdateCommand = cmdBuilder1.GetUpdateCommand()
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try
    End Function

But if I have more than one table in the query then it doesn't work.

What I am looking for is something like:-

Table Products              Table Sales

ProdId                          SalesId
PartNumber                  ProdId
Description                   Quantity
                                   Price

To show on the grid:-

Part Number                 Description                  Quantity      Price
ABC                             Spool                              1            10.00
DEF                             Washer                           2              0.20

I need to be able to amend the quantity and the price, but perhaps not the part number and the description, but to do so also in the one action would be of use
 
 
0
 
vb_jonasCommented:
Well, to update you will have to be sure that the update-command is ok. When you have more than one table you cannot use the commandbuilder.

Here's an example from MSDN (might look a bit hard, but try, and ask again if you're stuck):

Private Sub AdapterUpdate(ByVal connectionString As String)

    Using connection As SqlConnection = New SqlConnection( _
       connectionString)

        Dim adapter As SqlDataAdapter = New SqlDataAdapter( _
          "SELECT CategoryID, CategoryName FROM dbo.Categories", _
          connection)

        adapter.UpdateCommand = New SqlCommand( _
          "UPDATE Categories SET CategoryName = @CategoryName " & _
           "WHERE CategoryID = @CategoryID", connection)

        adapter.UpdateCommand.Parameters.Add( _
           "@CategoryName", SqlDbType.NVarChar, 15, "CategoryName")

        Dim parameter As SqlParameter = _
           adapter.UpdateCommand.Parameters.Add( _
           "@CategoryID", SqlDbType.Int)
        parameter.SourceColumn = "CategoryID"
        parameter.SourceVersion = DataRowVersion.Original

        Dim categoryTable As New DataTable
        adapter.Fill(categoryTable)

        Dim categoryRow As DataRow = categoryTable.Rows(0)
        categoryRow("CategoryName") = "New Beverages"

        adapter.Update(categoryTable)

        Console.WriteLine("Rows after update.")
        Dim row As DataRow
        For Each row In categoryTable.Rows
            Console.WriteLine("{0}: {1}", row(0), row(1))
        Next
    End Using
End Sub
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now