Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

vb.net windowsform DataGrid /dataset/update

Posted on 2004-09-21
11
Medium Priority
?
637 Views
Last Modified: 2010-08-05
hi,

I return a dataset (generated by storedProc) from a DLL to the client(windows form)  and bind it to vb.net DataGrid

Works fine. here is the code :

dim Obj as CPopulateDs
dim ds as new dataset
ds = Obj.getdata()  'function returns dataset to client
WindowsGrid.setdataBinding(ds,0)

Lets say dataGrid displays ID, firstName, LastName

Now I have 2 empty textboxes on form for displaying values of selected row when cliced on grid

TxtFirstname.text  =  ds.tables(0).DataGrid1.Items(DataGrid1.SelectedIndex).Cells(1).text

TxtLastName.text  = ds.tables(0).DataGrid1.Items(DataGrid1.SelectedIndex).Cells(2).text

Now the values are displayed in the textboxes. User can change and click update.

How can update be done in this scenario. what is that I have to do in the dll for update functionality
can an example be shown
0
Comment
Question by:sainavya1215
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
11 Comments
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 12119606
So you want to add update functionality in "CPopulateDs" class. That can be done. Create a sub there, which takes all these three fields as arguments. But make sure, that you store the ID with the click event of the Grid. Then just call that Sub using the same class object as you used for getdata().
-Baan
0
 

Author Comment

by:sainavya1215
ID: 12119788
should i update the DS used in previous code or should i write a different functioanlity for it instead of updating the dataset can an example be shown?
0
 

Author Comment

by:sainavya1215
ID: 12119840
SORRY there is change in code i posted........ Have i did the right thing. I want to update the Dataset (Dseries) used in my code.

I just need an example to be shown considering the folllowing code given below

here is the code:
Dim Dseries as new Dataset
DSeries = obj.GetDataset()
GrdGrid.setDatabinding(DSeries.Tables(0),"Nothing")


  Private Sub GrdBKSeries_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles GrdBKSeries.MouseUp

        Try
            Dim oInfo As DataGrid.HitTestInfo
            oInfo = Me.GrdGrid.HitTest(e.X, e.Y)
            Me.GrdGrid.Select(oInfo.Row)
            TxtFirstName.Text = dSeries.Tables(0).Rows(GrdBKSeries.CurrentCell.RowNumber).Item(1)
            TxtLastName.Text = dSeries.Tables(0).Rows(GrdBKSeries.CurrentCell.RowNumber).Item(2)
                 Catch ex As Exception
            MessageBox.Show(ex.Message.ToString, AppTitle)
        End Try


0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:sainavya1215
ID: 12119920
For test purpose I changed the text displayed in the 2 textboxes and in my updatebutton click event ... Though i changed the text i dont get the message "dataset data has changed" ... Whats going wrong. I want to update the same dataset used in my client form instead of just passing text values to be updated in my dll

if dSeries.haschanges then
       Messagebox.show("dataset data has changed")
         else
            Messagebox.show("dataset data hasnt changed")
end if

0
 
LVL 2

Expert Comment

by:ahmadfuwad
ID: 12120235
'take idx as global variable in the form
dim idx as integer

'code for set the textbox with the selected value
       Private Sub DataGrid1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.DoubleClick
        idx = Me.DataGrid1.CurrentRowIndex
        Me.TextBox1.Text = ods.Tables(0).Rows(idx).Item(1)
        Me.TextBox2.Text = ods.Tables(0).Rows(idx).Item(2)
    End Sub

'code for update dataset and datagrid at the same time by changing the value in textboxes
 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ods.Tables(0).Rows(idx).Item(1) = Me.TextBox1.Text
        ods.Tables(0).Rows(idx).Item(2) = Me.TextBox2.Text

    End Sub
0
 
LVL 18

Expert Comment

by:DotNetLover_Baan
ID: 12122550
>>"Though i changed the text i dont get the message "dataset data has changed" "<< this is happening because you are just displaying the two data fields in the textBoxes, not BINDING it. You have to change something that is bound. Only then your Dataset will recognize the changes.
-Baan
0
 

Author Comment

by:sainavya1215
ID: 12131728
DotNetLver,
if the textboxes values are changed
dSeries.Tables(0).Rows(GrdBKSeries.CurrentCell.RowNumber).Item(1) = me.textbox1.text
dSeries.tables(0).rows(GrdBkSeries.currentCell.rowNumber).item(2) = me.textbox2.text

Will this work... Will the dataset (dseries) take the new changes in the textboxes ........Should I call dseries.update after this statement or not??

0
 
LVL 18

Accepted Solution

by:
DotNetLover_Baan earned 2000 total points
ID: 12132859
try this..

dSeries.Tables(0).Rows(GrdBKSeries.CurrentCell.RowNumber).Item(1) = me.textbox1.text
dSeries.tables(0).rows(GrdBkSeries.currentCell.rowNumber).item(2) = me.textbox2.text
dSeries.AcceptChanges()
'Then update

-Baan
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question