Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two windows, (Form1 and EditRecord). On Form1 there is a gridview that is populated by a fill query (SQL Database). I want the user to select a record from the table and click btnEdit record to move the selected record to a new window. The following code is what I have in my EditRecord window. The key column in my SQL query is GUID. I have written a SQL query that parametizes the GUID and I've called that FillByGUID. Here is the code on my EditRecord window:

C#
internal void LoadOrders(String GUID)
       {
           this.cj96TBRiscTableAdapter.FillByCustomerID(this.cj96DataSet.cj96TBRisc, GUID);
       }



Can someone please help me on this? If you need any other information let me know and I'll post it.
Posted

Exactly how you do this depends on the relationship between the forms: If you create an instance of one in another, then the first is the parent, the second is the child:
Transferring information between two forms, Part 1: Parent to Child[^]
Transferring information between two forms, Part 2: Child to Parent[^]
Transferring information between two forms, Part 3: Child to Child[^]
 
Share this answer
 
Comments
Maciej Los 26-Feb-14 11:46am    
+5
Change your EditRecord form's constructor to accept a string as a parameter.

private string GUID;

public EditRecord(string GUID)
{
     this.GUID = GUID;
}


Then when you initialise EditRecord in Form1 pass the value into the constructor.

EditRecord editRecord = new EditRecord(GUID);
editRecord.Visible = true
 
Share this answer
 
Comments
Branden Coker 26-Feb-14 9:42am    
Thank you so much Paddy84! You have helped me out tremendously.
Paddy84 26-Feb-14 9:48am    
No problem at all. This will work from parent to child but to pass data back and forth you should read OriginalGriff's articles in the solution below. They are easy to follow and very well explained.

Take care.

Paddy
Branden Coker 26-Feb-14 10:09am    
Thank you also for the Solution OriginalGiff. I will read through the articles you've supplied me. Cheers!
Maciej Los 26-Feb-14 11:46am    
+5
Branden Coker 27-Feb-14 9:17am    
One more question. I thought I had it working and I'm not getting any errors, but when I launch the EditRecord form, now my form isn't populating. Here is the EditRecord code (if you have a chance):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WFRiscIDAdmin
{
public partial class EditRecord : Form
{
private Guid GUID;
public EditRecord(Guid GUID)
{
this.GUID = GUID;
InitializeComponent();
}

private void cj96TBRiscBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.cj96TBRiscBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.cj96DataSet);


}

private void EditRecord_Load(object sender, EventArgs e)
{

}

internal void EditRecord_Selected(Guid GUID)
{
this.cj96TBRiscTableAdapter.FillByGuid (this.cj96DataSet.cj96TBRisc, GUID);
}

private void btnCancelChanges_Click(object sender, EventArgs e)
{
this.Close();
}
}
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900