How to use one datagrid to update/insert into another

S

shookim

I don't care how one suggests I do it, but I've been searching for days
on how to implement this concept. I'm trying to use some kind of grid
control (doesn't have to be a grid control, whatever works best) to
display a dropdown menu of fields populated from table tblInvoiceData.
This control also includes a textbox which the user can input a value.
These two columns are side by side and not in a vertical layout.

The user then clicks on the "add" button and that particular field and
value displays in a grid (can be this original grid or another), BUT,
does not update the database tables until the user finshes adding all
their fields and then clicks on the UPDATE button, at which point
updates tblInvoiceData for this particular clientID.

HELP!!!
 
R

RobinS

How many times are you going to re-post this? Cor's response
means this: You are asking too broad a question.

If the first control has only one value, use a combobox.
Bind it to your tblInvoiceData. Put a textbox next to it.
Put a button next to that. Add an event handler to the
button.

Put a grid on the bottom. When they click on the <Add> button,
add a record to the grid.

I think that's what you're going for. Tackle the problems
one at a time. It seems like you're asking us to write the
whole thing for you. I'd do that for you, but you'll have
to send me a billing address... ;-)

Robin S.
 
S

shookim

Moreso, I think his response is saying I'm asking too specific a
question. I've actually done what you've described there, but the
problem with that is once the user tries to add another item, it
replaces the first value added to the 2nd grid.
 
R

RobinS

No, you're asking too broad a question. It's like someone
posted a question "Tell me about Windows Forms". Or "Tell me
about ADO.Net". Well, there are books of over a thousand
pages, how do you answer that in a newsgroup? Go buy a book.

This is a more specific question. Are you adding a row
to the 2nd grid before putting the values in? How are you
putting the values in / adding the information to the grid?
Post that code, and we can help you with it.

Robin S.
----------------------------------------
 
S

shookim

look, I'm not going to argue about this. The whole point of stating my
initial problem was for someone to possibly suggest a concept or
method, if there's something already out there that does something like
this. If not, I gave a specific example of what I'm trying to do.
 
S

shookim

here's the code.

Dim cmdParam As SqlParameter
Dim ddlField As String = CType(e.Item.FindControl("ddlField"),
DropDownList).SelectedValue
Dim txtValue As String = CType(e.Item.FindControl("txtValue"),
TextBox).Text
Sub dgMassUpdate_Insert(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)

dsMassUpdate = Session("dsMassUpdate")
dsMassUpdate.Tables("MassUpdate").Rows(0).Item(ddlField) = txtValue

SqlConn.ConnectionString =
ConfigurationSettings.AppSettings("ConnectionString")
dgMassUpdate.EditItemIndex = -1

dgTemp.DataSource = dsMassUpdate
dgTemp.DataSource = CreateDataSource(ddlField, txtValue)

End Sub

Function CreateDataSource(ByVal ddlField As String, ByVal txtValue
As String) As ICollection
Dim table As New DataTable
Dim tr As DataRow
Dim td As DataColumn
Dim newRow As DataRow
newRow = table.NewRow()

table.Columns.Add(New DataColumn(ddlField, GetType(String)))
table.Columns.Add(New DataColumn(txtValue, GetType(String)))

Dim dv As New DataView(table)
Return dv
End Function
 
S

shookim

oops, here it is again...

Sub dgMassUpdate_Insert(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
Dim cmdParam As SqlParameter
Dim ddlField As String = CType(e.Item.FindControl("ddlField"),
DropDownList).SelectedValue
Dim txtValue As String = CType(e.Item.FindControl("txtValue"),
TextBox).Text

dsMassUpdate = Session("dsMassUpdate")
dsMassUpdate.Tables("MassUpdate").Rows(0).Item(ddlField) =
txtValue

SqlConn.ConnectionString =
ConfigurationSettings.AppSettings("ConnectionString")
dgMassUpdate.EditItemIndex = -1

dgTemp.DataSource = dsMassUpdate
dgTemp.DataSource = CreateDataSource(ddlField, txtValue)

End Sub

Function CreateDataSource(ByVal ddlField As String, ByVal txtValue
As String) As ICollection
Dim table As New DataTable
Dim tr As DataRow
Dim td As DataColumn
Dim newRow As DataRow
newRow = table.NewRow()

table.Columns.Add(New DataColumn(ddlField, GetType(String)))
table.Columns.Add(New DataColumn(txtValue, GetType(String)))

Dim dv As New DataView(table)
Return dv
End Function
 
S

shookim

Sub dgMassUpdate_Insert(ByVal sender As Object, ByVal e As
DataGridCommandEventArgs)
Dim cmdParam As SqlParameter
Dim ddlField As String = CType(e.Item.FindControl("ddlField"),
DropDownList).SelectedValue
Dim txtValue As String = CType(e.Item.FindControl("txtValue"),
TextBox).Text

dsMassUpdate = Session("dsMassUpdate")
dsMassUpdate.Tables("MassUpdate").Rows(0).Item(ddlField) =
txtValue

SqlConn.ConnectionString =
ConfigurationSettings.AppSettings("ConnectionString")

dgTemp.DataSource = CreateDataSource(ddlField, txtValue)

End Sub

Function CreateDataSource(ByVal ddlField As String, ByVal txtValue
As String) As ICollection
Dim table As New DataTable
Dim tr As DataRow
Dim td As DataColumn
Dim newRow As DataRow
newRow = table.NewRow()

table.Columns.Add(New DataColumn(ddlField, GetType(String)))
table.Columns.Add(New DataColumn(txtValue, GetType(String)))

Dim dv As New DataView(table)
Return dv
End Function
 
R

RobinS

Fair enough. I think it came across as one of those really
broad questions, and that's why you got the response you did.

I'll go look at your other posts, and if I can help you, I will.

Robin S.
-----------------------------
 
R

RobinS

Well, right off the bat, without completely understanding
everything, this looks like an issue:

dsMassUpdate.Tables("MassUpdate").Rows(0).Item(ddlField) =
txtValue

If you use Rows(0), it will always put it in the first row.

Is dbMassUpdate your data grid that you are inserting their
selection into? What is dgTemp?

If anybody else out there has an opinion, please feel free to
chime in!

Robin S.
-------------------------------
 
S

shookim

my main dataset is dsMassUpdate which I fill early in early piece of
the code. dgMassUpdate is the first datagrid, where I'm performing the
update to the dataset. dgTemp is the second datagrid which gets
populated with the field and value from the first datagrid.

What I'm trying to do is allow the user to update each field with a
value they enter by updating the dataset and not the database. When
the user is finally finished with selecting all the fields and adding
values for the field to be updated with, THEN they hit the UPDATE
button which updates the db.

The purpose of the second datagrid was just to display what fields and
values the user selected and entered. This data doesn't actually get
updated to the database immediately.
 
R

RobinS

Okay, let me try this again:

dsMassUpdate is your actual dataset that is going to be updated?

dgMassUpdate is a datagrid that shows the dataset dsMassUpdate?
Or does it show a list of fields in dsMassUpdate? So they pick
a field name and put the new value in the textbox and click a
button and it adds it to dgTemp?

Then when they're done, they apply all the updates to the
dataset dsMassUpdate?

Am I understanding your process yet?

Robin S.
-------------------------------------------
 
S

shookim

That is correct.
Okay, let me try this again:

dsMassUpdate is your actual dataset that is going to be updated?

dgMassUpdate is a datagrid that shows the dataset dsMassUpdate?
Or does it show a list of fields in dsMassUpdate? So they pick
a field name and put the new value in the textbox and click a
button and it adds it to dgTemp?

Then when they're done, they apply all the updates to the
dataset dsMassUpdate?

Am I understanding your process yet?

Robin S.
 
S

shookim

Yes, dgMassUpdate binds the query that holds all the fields that are
populated in the dropdownlist. dgMassUpdate doesn't actually list
anything. The only thing dgMassUpdate does, event wise, is fire
dgMassUpdate_Insert(). And Yes, you are correct, that event then calls
CreateDataSource(). And then the update button does a update of all
the fields and values they've entered. Would you like me to send you
the actual code, so you can see it?

Thanks, I appreciate the help!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top