updating a datagrid using a data adpater and data set



  • 1. Formatting decimal variable
    Try myString = myDecimal.ToString("g3"); 3 is significant number >-----Original Message----- >When formatting a decimal variable, is there a format >string that will show decimals only when they are non- zero? > >For example, I would like the following values to be >converted to strings like this: > > 1 = 1 > 1.7 = 1.7 > 1.25 = 1.25 > >If I use > >myString = myDecimal.ToString("n2"); > >I get > > 1 = 1.00 > 1.7 = 1.70 > 1.25 = 1.25 > >and if I use > >myString = myDecimal.ToString("n0"); > >I get > > 1 = 1 > 1.7 = 2 > 1.25 = 1 > >Neither of these is quite what I'm after. > >Thanks, >Ric > >. >
  • 2. Prevent people from using my dll's
    How do I prevent other people from using the dll's I create? I looked at identity permissions but it looks like those are more for identifying an assembly. Any help would be great. Thanks!!
  • 3. Sample code for adding checkboxs in a DataGrid
    Where I can find sample code for adding checkboxs in a DataGrid? Thanks
  • 4. datagrid - how to clear
    this.dataGrid1.DataSource=null; this.al.Clear(); //clear arraylist this.dataGrid1.DataSource=al; >-----Original Message----- >reposted here as no response in >dotnet.framework.windowsforms - >how do i clear all data from a datagrid whose datasource >was an arraylist? > >me >. >

updating a datagrid using a data adpater and data set

Postby Terry Knight » Fri, 10 Oct 2003 09:00:42 GMT


i've created a data adpater called 'dabvscores'
i've created a dataset called 'dsvbscores'

now i've greated a private sub to populate the data adpater and then i fill
the dataset and this private is called on form load, i have an update
command button with the following code in it:

but i'm getting an error when it try to run the code.  does anyone know what
i'm doing wrong???

Terry Knight
Computer Systems Technologist
F:  206.260.0704

Re: updating a datagrid using a data adpater and data set

Postby Matt Burland » Fri, 10 Oct 2003 11:08:41 GMT

What error are you getting? What were you expecting to happen? Did you
either set the Select, Insert, Update and Delete commands of the data
adapter or use the command builder?
BTW, you populate the dataset, not the data adapter. The data adapter just
acts a kind of "middle man" between your dataset and your datasource. This
lets you use your dataset the same way regardless of what the datasource


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 


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
            If OleDbConnection1.State = ConnectionState.Closed Then
                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
        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
        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;
				LblResult.Text = "Not Updated";
			//End editing
			dgCustomers.EditItemIndex = -1;
			//Update the database
			//And bind data to the ui

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 

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
            Dim cmd2 As New SqlClient.SqlCommand
            cmd2.CommandText = "c_sp_manager_access"
            cmd2.CommandType = CommandType.StoredProcedure
            cmd2.Connection = SqlConnection1
            Dim myparam As New SqlClient.SqlParameter
            myparam.ParameterName = "@UserName"
            myparam.Direction = ParameterDirection.Input
            myparam.SqlDbType = SqlDbType.VarChar
            myparam.Value = username
            SqlDataAdapter1.SelectCommand = cmd2
            SqlDataAdapter1.Fill(DataSet31, "c_sp_manager_access")

        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

Return to dotnet-framework


Who is online

Users browsing this forum: No registered users and 30 guest