Similar Threads:
1.Data Adapters, Data Sets, Data TableMappings, and XML
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
2.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) "
3.Using a CheckBox in a DataGrid to Update a Bit Type Data Field
4.Using the datagrid update command to alter data in a dataset
I have managed to get succesfully working the , delete and cancel functions working within the datagrid to alter data held in dataset that then
updates a SQL Database.
When I click edit the correct row changes into textboxes to make the changes. Then when I click update is when I get stuck. I am using the datagrid
(dgCustomers) items index and DataKeyField (CustomerID) to search for the correct row within the dataset, to update.
here is the code:
private void dgCustomers_UpdateCommand(object source, system.Web.UI.WebControls.DataGridCommandEventArgs e)
{
// //Test Label to see the value of the datakey is correct
Label6.Text = dgCustomers.DataKeys[e.Item.ItemIndex].ToString();
//Select correct row using the index and datakeyfield.
DataRow[] adrEdit = ds.Tables["Customers"].Select("CustomerID = 'dgCustomers.DataKeys[e.Items.ItemIndex]'");
//Make sure there is data
if(adrEdit.Length > 0)
{
//Put in the edited data
TextBox txtCompanyName = (TextBox) e.Item.Cells[3].Controls[0];
adrEdit[0]["CompanyName"] = txtCompanyName.Text;
TextBox txtContactName = (TextBox) e.Item.Cells[4].Controls[0];
adrEdit[0]["ContactName"] = txtContactName.Text;
}
else
{
LblResult.Text = "Not Updated";
}
//End editing
dgCustomers.EditItemIndex = -1;
//Update the database
da.Update(ds,"Customers");
//And bind data to the ui
LoadData();
}
For some reason it doesn't find the necessary data and skips the if loop. The test label(label6) however does return the value of a customerID suck as
ALFKI.
If I replace this row
DataRow[] adrEdit = ds.Tables["Customers"].Select("CustomerID = 'dgCustomers.DataKeys[e.Items.ItemIndex]'")
With this more explicit statement
DataRow[] adrEdit = ds.Tables["Customers"].Select("CustomerID = 'ALFKI'")
It actually works, but obviously updates only the ALFKI row. Can anyone shed any light on where I may be going wrong, or is it just my comp playing
funny buggers with me again!
Many thanks
Paul Custance
5.Update SQL Table Data using DataGrid
Hello All,
Is it possible to update Sql Table through DataGrid. I have a DataGrid
which is being populated through a stored procedure, all i wanted to do
is to update one field (FieldName-Authorised) which has a datatype bit
through DataGrid but not sure how to go about it. Any Ideas Guys on
this one, your help is greatly appreciated.
This is the procedure used to populate the datagrid, The primary key
for the table is EntryID which is displayed on the datagrid. I need to
update only one column based on the entryid, is that possible.
Private Sub FillData()
Dim username As String
username = lblUser.Text.Trim
Try
Dim cmd2 As New SqlClient.SqlCommand
cmd2.CommandText = "c_sp_manager_access"
cmd2.CommandType = CommandType.StoredProcedure
cmd2.Connection = SqlConnection1
cmd2.Parameters.Clear()
Dim myparam As New SqlClient.SqlParameter
myparam.ParameterName = "@UserName"
myparam.Direction = ParameterDirection.Input
myparam.SqlDbType = SqlDbType.VarChar
myparam.Value = username
cmd2.Parameters.Add(myparam)
SqlDataAdapter1.SelectCommand = cmd2
SqlDataAdapter1.Fill(DataSet31, "c_sp_manager_access")
DataGrid1.DataBind()
Catch ex As Exception
Dim debug As String = ex.Message
lblfeedback.Text = ex.Message
End Try
End Sub.
I have written a stored procedure to update the column, it takes the
following parameters
EntryID, Authorised(Value either True or False), EditedBy(String).
Now how do i use this stored procedure in the datagrid to update my sql
table. Please advice.
Thanks in Advance, Shilpa.
6. display data in a DataGrid - update using a form
7. How can I update data using a Details view without using an AccessDataSource
8. MDB is not Updated only data Set