Data Adapters, Data Sets, Data TableMappings, and XML

dotnet framework

    Next

  • 1. How to kow the Lenght of the Text in the Current DataGridTextBoxColumn (on MouseMove)
    Hi, I need to know the Lenght of the Text in a DataGridTextBoxColumn when I move with the mouse over it, and show it in a ToolTip. I have something that works, but it works only when the DataGridextBoxColumn is not selected. Once I select it (type some additional text in it), I don't see the ToolTip anymore... I gues that's because it isn't anymore the DataGrid that the Mouse is moving over, but the Cell. Does anybody knows a solution for this? Thanks a lot in advance, Pieter You can see my DataGrid_MouseMove here: Private Sub dbgGrid_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dbgGrid.MouseMove Dim p1 As New Point p1 = dbgGrid.PointToClient(Cursor.Position) Dim intCol As Integer = dbgGrid.HitTest(p1).Column Dim intRow As Integer = dbgGrid.HitTest(p1).Row If (intCol = 3) And (intRow > -1) Then Dim strT As String Try strT = dbgGrid.Item(intRow, intCol).ToString Catch ex As Exception strT = "" End Try strT = strT & vbCrLf & "Length: " & strT.Length totImport.SetToolTip(dbgGrid, strT) totImport.Active = True Else totImport.SetToolTip(dbgGrid, "") totImport.Active = False End If End Sub
  • 2. Getting XML as string
    Hi I'm a bit new to this so here goes my question: I need to get the XML from a dataset as a string. I've been beating my head against the wall trying to use the overload methods of the [mydataset].WriteXML methods but with no sucess. I'm sure I'm missing something easy.. Can anyone lend a hand? TIA Steve
  • 3. Quirky DataGrid behavior
    Hey you guys, How's it going? I have a Parent/Child/GrandChild relationship, and I have all my controls, including three DataGrids, bound to the database using the BindingMangerBase object (I've also tried the CurrencyManager with the same results). Also, each BindingManagerBase object is associated to its own PositionChanged event. When any or all of the DataGrids are visible, their respective PositionChanged event "fires" no problem. However, whenever any of them are hidden the PositionChanged event quits working. For instance, when I hide the DataGrid that's bound to the parent table its PositionChanged event stops firing. This is also true if I hide the DataGrid that's bound to the child table also. Other than this quirk everything works fine. Very baffled
  • 4. Cascade updates on primary keys..
    Is there a way to do this safely? I'm using MSDE and have two tables that are linked via 3 fields. If one of those fields change, I need the update to cascade through the child file. There is a relation on the tables on the server and on the tables in the dataset... Every time I try to do an Update, if those fields have changed or if none have changed, I get this error: "The query processor cound not produce a query plan from the optimizer because a query cannot update a text, ntext, or image column and a clustering key at the same time. I remember having this before and I had to remove the key columns from the update command, however that was a situation where the primary key will never change. This one will... I don't know if it's related or not, but doing an AddNew on the bindingcontext of the parent file no longer adds a new row. It gets added, but the current position is always 0. Trying to navigate to that row doesn't work either... Aaron -- --- Aaron Smith Remove -1- to E-Mail me. Spam Sucks.
  • 5. Still stuck on DataRelation names
    Hi, I've created an xml instance document named "test.xml" and from that created an associated schema document named "test.xsd". I have used the schema designer to add three primary keys and two relations. I have named the relations "RelationDocumentItems" and "RelationItemsItem". When I create a DataSet in code using ReadXml("test.xml") and then read the names of the relations in DataSet.Relations I get "TestDocument_TestItems" and "TestItems_TestItem" rather than the expected "RelationDocumentItems" and "RelationItemsItem" ( my expectation). Can someone please help me understand where my names went? Thanks Jeff Higgins

Data Adapters, Data Sets, Data TableMappings, and XML

Postby Candi Suriano » Sun, 24 Aug 2003 04:46:17 GMT

Here's what I'm trying to do:

1. Create a data adapter with Select and Insert commands.

2. Use DataTableMappings to map XML tags into columns in a 
data base table.

3. Create a dataset

3. Read in a schema using dataset.ReadXmLSchema

4. Read in an xml file that contains the data using 
dataset.Read XML

5. Add 3 new columns to the dataset. (These columns have 
already been mapped in step 2).

6. Put data in the 3 new columns.

7. Modify some data in the other columns using xpath 
queries to find the nodes that need changing.

8. Use datadapter.update(dataset, tablename)

Everything seems to work fine until step 8. I get all the 
data, the extra columns get added, and the data in other 
columns gets modified. When I execute step 8 I get:

Run-time exception thrown : 
System.InvalidOperationException - Cannot add or remove 
columns from the table once the DataSet is mapped to a 
loaded XML document.

Any ideas about how I can either fix this or do it another 
way.

TIA,
Candi

Similar Threads:

1.problem with data adapter and data set while inserting and retrieving data

i am using a data adapter and a dataset for filling and retrieving data
into .mdb database.
following is the code.....

for the form load event
  Dim dc(0) As DataColumn
        Try
            If OleDbConnection1.State = ConnectionState.Closed Then
                OleDbConnection1.Open()
            Else
                MsgBox("connection can not be established")
            End If
            DA.Fill(DataSet11, "Table1")
            cmd = New OleDbCommandBuilder(DA)
            dc(0) = DataSet11.Tables("Table1").Columns("EmpID")
            DataSet11.Tables("Table1").PrimaryKey = dc
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Delete.Enabled = False
    End Sub

for  inserting values into the DB

Private Sub Insert_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Insert.Click
        Dim dr As DataRow
        dr = DataSet11.Tables("Table1").NewRow
        dr.Item(0) = Val(TB1.Text)
        dr.Item(1) = TB2.Text
        dr.Item(2) = TB3.Text
        dr.Item(3) = Val(TB4.Text)
        dr.Item(4) = TB5.Text
        DataSet11.Tables("Table1").Rows.Add(dr)
        DA.Update(DataSet11, "Table1")
        MsgBox("data is saved")
        rno = 0
        call filldata()

filldata function consists of the following

 With DataSet11.Tables("Table1").Rows(rno)
         TB1.Text = Trim(.Item(0))
         TB2.Text = Trim(.Item(1))
         TB3.Text = Trim(.Item(2))
         TB5.Text = Trim(.Item(4))
         End With

the error it gives is " there is no row at
0........system.nullreference...........i checked the connection and
its working fine and also the database is getting accessed........the
error is occuring at the line " With
DataSet11.Tables("Table1").Rows(rno) "

2.Passing parameter for Stored Procedure to Data Adapter/Data Set

Hey all,

   I'm trying to pass a parameter into my Stored procedure to be accessed by 
my data adapter into a dataset

            db2.AddParameter("@intClientID", 
cmbClientList.SelectedValue.ToString());
            DataSet rsDataset = db2.Fill("spListMappingDetails", 
CommandType.StoredProcedure);

However, when i try to run it, it gives me an error 

{"Procedure 'spListMappingDetails' expects parameter '@intClientId', which 
was not supplied."}

Any help is appreciated.

I used a executescalar and executequery function and it has no problem. 

thanks in advance

3.Provider independent data access: creating a data adapter from a connection

I have written a provider independent ado.net utility class for 
executing queries. One of the routines looked like this in .net 1.1:

static public DataSet ExecuteQuery(IDbConnection connection, String sql)
{
   connection.Open();

   DataSet result  = new DataSet();
   IDbDataAdapter adapter = /* magic to create an adapter from a 
connection*/

   // The sybase adapter's implement IDisposable, so wrap with a using. 

   using(adapter as IDisposable)
   {
     adapter.SelectCommand.CommandText = sql;
     adapter.SelectCommand.Connection = conn;
     adapter.Fill(result);
   }

   return result;
}

The magic code to create the adapter was ugly: it essentially performed 
a dictionary lookup on the type of connection, and created the resulting 
adapter type. If IDbConnection had a method called CreateAdapter, 
analagous to CreateCommand, this would have been cleaner.

With the introduction of ADO.NET 2.0 and the DbProviderFactory class, I 
was hoping that some of the ugliness would go away. Unfortunately, I am 
running into some problems. Namely

1- DbConnection still does not have a CreateAdapter method

2- DbConnection does not offer a way to get back to the 
DbProviderFactory that created it.

So I still cannot create the correct adapter given only a generic 
DbConnection. I am looking for suggestions on how to code my routine. So 
far, I have thought of these

1- Make the user pass in the DbProviderFactory that goes with the 
connection. CONS: forces users to use DBProviderFactory. We have a lot 
of code that doesn't.

2- Stick with the dictionary lookup (Dictionary<ConnType, AdapterType>. 
CONS: DLL dependencies explode.

3- Use a different dictionary lookup (Dictionary<ConnType, 
DBProviderFactory>. CONS : A little messy, but better than 2.

4- Don't use provider specific adapters at all, just use a generic one. 
Like this:

class GenericAdapter : System.Data.Common.DbDataAdapter
{
}

static public DataSet ExecuteQuery(DbConnection connection, String sql)
{
   connection.Open();

   DataSet result  = new DataSet();
   GenericAdapter adapter = new GenericAdapter();
   adapter.SelectCommand = conn.CreateCommand();
   adapter.SelectCommand.CommandText = sql;
   adapter.Fill(result);
   return result;
}

I have tested this with two databases, Sybase ASE and ASA, and it seems 
to work. Are there any serious downfalls to not using the vendor 
specific adapter type? Is this code safe?

H^2

4.Passing parameter for Stored Procedure to Data Adapter/Data Se

5.Manipulating data between data adapters

Hi

I have two data adapters bound to two separate tables. How can I;

1. Loop through all records one by one in one of them while reading column 
values, and

2. Insert a record from data adapter A into data adapter B

via code?

Thanks

Regards


6. How to change data in grid after you change the SQL select for the data adapter

7. 3rd Tier data not displaying in Data Adapter Preview

8. How to change data in grid after you change the SQL select for the data adapter



Return to dotnet framework

 

Who is online

Users browsing this forum: No registered users and 38 guest