Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have two mdi child forms one mdi child form displays all the registered users details with edit buttons for all rows, when the edit button is pressed and update form should be displayed with the existing details of the person present in the row where edit button is pressed..
but for my code only empty update page is being diplayed ..
plz help with binding data to update form..
Posted
Comments
Sergey Alexandrovich Kryukov 6-Sep-13 1:27am    
There are too many ways to screw up things. Without seeing your code, it's hard to see what's wrong.
—SA
Member 10256223 6-Sep-13 1:33am    
i have given my code here plz check and say whats wrong

Here is the idea: who needs MDI, ever? Why torturing yourself and scaring off your users?
Do yourself a great favor: do not use MDI at all. You can do much easier to implement design without it, with much better quality. MDI is highly discouraged even by Microsoft, in fact, Microsoft dropped it out of WPF and will hardly support it. More importantly, you will scare off all your users if you use MDI. Just don't. Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
How to Create MDI Parent Window in WPF?[^].

I can explain what to do instead. Please see my past answers:
How to Create MDI Parent Window in WPF? [Solution 2],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to set child forms maximized, last childform minimized[^].

—SA
 
Share this answer
 
Comments
BillWoodruff 6-Sep-13 3:06am    
Hi Sergey, I think you know, by now, that I share your view that MDI is the worst possible way to manage multiple Forms (WinForms), or Windows (WPF), and should be "shot" :) And, that I also share your view that the idea of ever (in WinForms) setting the Parent of a Form to some other Form is, equally, an abomination (is there an equivalent atrocity that can be performed in WPF ?).

Perhaps, when you wrote this reply, the OP had not yet added the words "Windows Forms" to the title of their question ?

The "sad hypothesis" that I have formed, here on CP Q&A ... an inference from the number of MDI related questions seen here ... is that, unfortunately, a lot of students are being taught to use MDI, and expected to use it (I assume, often a part of their home-work). And, I assume there's another unhappy lot who actually have to work on existing complex legacy applications using MDI.

So: I'll keep throwing out "life-preservers," as best as I can, to the thrashing, about-to-go-under, souls burdened with MDI :) But, that's my choice, and I am not, in any way, suggesting that should be your choice !
Sergey Alexandrovich Kryukov 6-Sep-13 11:41am    
Thank you, Bill.

This is an interesting comment, but it leaves me a bit puzzled. It looks like your view on MDI in general, and on my way of answering such question in particular has changes since my last answer to the similar question. You could have noted that answer was identical. I also did not clearly understand what is your choice you mentioned.

A few words on this matter. Your assumptions on where such MDI works come from is interesting. I myself have developed a pretty big MDI-based system when MDI was a common place and soon realized that it was my mistake, even though MDI was readily available and single-form techniques like docked panels not really supported. And it was many years ago. If people are taught and required to use MDI, this is not itself a big disaster (for good students), but it is very indicative: it shows that the teaching is done by mastodons who repeat the same things year by year and don't do life work and don't learn anything themselves. This is wrong and sad.

And this is not a wrong thing. By regular references from students on this site, one can see that such a shameful phenomenon as nearly fake education in "computer science" flourishes (so I could not write "computer science" without quotation marks). This MDI thing, if your assumption is correct, is one of the least fundamental flaws. Faking fundamental things is much worse.

And one more thing about "expected to use". I realized that the central point of engineering and most difficult part of profession is. This is not taking orders and not doing something which is wrong, even when pressed to do so.

—SA
This is my code for the child form which displays all the registered user details with edit buttons

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

namespace WindowsFormsApplication2
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)
{
DataSet set = GetRegisteredUsers();
dataGridView1.DataSource = set.Tables[0];
DataGridViewButtonColumn EditColumn = new DataGridViewButtonColumn();
EditColumn.Text = "Edit";
EditColumn.Name = "Edit";
EditColumn.DataPropertyName = "Edit";
dataGridView1.Columns.Add(EditColumn);
EditColumn.UseColumnTextForButtonValue = true;

}

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{

//RegisterUser frm = new RegisterUser();
//frm.Show();
Profile childForm = new Profile();
childForm.MdiParent = (Form)this.Parent.Parent;
//childForm.Text = "Window ";
childForm.Show();
}
public DataSet GetRegisteredUsers()
{
try
{
//local variables
DataSet ds = new DataSet();
//creating conection object
SqlConnection con = new SqlConnection();
// connection string
con.ConnectionString = @"Data Source=AGILE\SBSMONITORING;Initial Catalog=Training_Alekhya;Persist Security Info=True;User ID=sa;Password=agile_sa@2011";

SqlCommand cmd = new SqlCommand();
{
//set up command object
SqlDataAdapter da = new SqlDataAdapter("(select * from Registration)", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandTimeout = 0;
//opening connection
if (con.State != ConnectionState.Open)
{
con.Open();
}
//executing the query and filling the data set
da.Fill(ds);
//close connection
con.Close();
//returning the result of stored procedure
return ds;

}
}
catch (Exception ex)
{
MessageBox.Show("exception caught:" + ex.ToString() + ".", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
}
}
}



and this is my code for update page


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

namespace WindowsFormsApplication2
{
public partial class Profile : Form
{
SqlConnection con;
SqlCommand cmd;
SqlDataReader rdr;
public Profile()
{
InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)
{
try
{
string gender = "";
if (radioButton1.Checked == true)
{
gender = "M";
}
else if (radioButton2.Checked == true)
{
gender = "F";
}
// creating conection object
SqlConnection con = new SqlConnection();
//creating a conection string
con.ConnectionString = @"Data Source=AGILE\SBSMONITORING;Initial Catalog=Training_Alekhya;Persist Security Info=True;User ID=sa;Password=agile_sa@2011";
//SqlDataAdapter adp = new SqlDataAdapter("insert into Registration values( @UserName,@Password,@ConfirmPassword,@Phone,@Email,@Address,@Gender,@AccessRights)", con);
//SqlCommand cmd = new SqlCommand();



con.Open();
SqlCommand cmd = new SqlCommand("Update_table", con);
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.Add(new SqlParameter("@UserName", textBox1.Text));
cmd.Parameters.Add(new SqlParameter("@Password", textBox2.Text));
cmd.Parameters.Add(new SqlParameter("@Gender", gender));
cmd.Parameters.Add(new SqlParameter("@Email", textBox5.Text));
cmd.Parameters.Add(new SqlParameter("@Phone", textBox4.Text));
cmd.Parameters.Add(new SqlParameter("@Address", textBox6.Text));
cmd.Parameters.Add(new SqlParameter("@AccessRights", comboBox1.SelectedItem));
cmd.Parameters.Add(new SqlParameter("@userid", 1));
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(("select * from Registration where userid = @userid"), con);

int nr = cmd.ExecuteNonQuery();
if (nr > 0)
{
this.Hide();
Form1 lgn = new Form1();
lgn.ShowDialog();
MessageBox.Show("Saved");
}
else
MessageBox.Show("Not Saved");
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}

}


// {
// string Gender = "";
// if (radioButton1.Checked == true)
// {
// Gender = "m";
// }
// else if (radioButton2.Checked == true)
// {
// Gender = "f";
// }

// //creating conection object
// //SqlConnection con = new SqlConnection();
// //creating a conection string
// //con.ConnectionString = @"Data Source=AGILE\SBSMONITORING;Initial Catalog=Training_Alekhya;Persist Security Info=True;User ID=sa;Password=agile_sa@2011";
// //SqlDataAdapter adp = new SqlDataAdapter("insert into Registration values( @UserName,@Password,@ConfirmPassword,@Phone,@Email,@Address,@Gender,@AccessRights)", con);
// //SqlCommand cmd = new SqlCommand();
// //cmd.Connection = con;
// //changing conection string to stored procedures
// cmd.CommandType = CommandType.StoredProcedure;
// cmd.CommandText = "dbo.Update_table";
// //"insert into Registration values( @UserName,@Password,@ConfirmPassword,@Phone,@Email,@Address,@Gender,@AccessRights)";
// cmd.Parameters.AddWithValue("@UserName", textBox1.Text);
// cmd.Parameters.AddWithValue("@Password", textBox2.Text);
// //cmd.Parameters.AddWithValue("@ConfirmPassword", textBox3.Text);
// cmd.Parameters.AddWithValue("@Phone", textBox4.Text);
// cmd.Parameters.AddWithValue("@Email", textBox5.Text);
// cmd.Parameters.AddWithValue("@Address", textBox6.Text);
// cmd.Parameters.AddWithValue("@Gender", Gender);
// //cmd.Parameters.AddWithValue("@Gender", radioButton2.Checked);
// cmd.Parameters.AddWithValue("@AccessRights", comboBox1.SelectedItem);
// //textBox1.Text=(("Select UserName from Registration where UserId = @UserId"), con);

// // try
// // {
// // if (textBox2.Text == textBox3.Text)
// // {
// // con.Open();//establishes phy link between App and DB
// cmd.ExecuteNonQuery();
// // MessageBox.Show("You have been registered");
// // this.Hide();
// // Form1 lgn = new Form1();
// // lgn.ShowDialog();
// // }

// // else
// // {
// // MessageBox.Show("does not match");
// // textBox3.Clear();
// // textBox3.Focus();
// // }
// // }
// // catch (SqlException ex)
// // {
// // MessageBox.Show(ex.Message);
// // }
// // finally
// // {
// if (con.State == ConnectionState.Open)
// {
// con.Close();
// }
// // }
// }

private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
{
if (char.IsDigit(e.KeyChar) == true)
{
if (textBox4.Text.Length < 10)
{
//MessageBox.Show("invalid mobile no");
}
else
{
MessageBox.Show("Max 10 chars");
e.Handled = true;
}
}
else
{
e.Handled = true;
}
}

private void Profile_Load(object sender, EventArgs e)
{

//Form.DataSource = bindingSource1;
//GetData("select * from Customers");

con = new SqlConnection("Data Source=192.168.1.2;database=Training_Reshma;Persist Security Info=True;User ID=sa;Password=agile_sa@2011");
con.Open();
cmd = new SqlCommand("Select * from tblregistration", con);
rdr = cmd.ExecuteReader();
con.Close();
}
}
}
 
Share this answer
 
Comments
BillWoodruff 6-Sep-13 2:53am    
Hi Member 10256223, This is not an answer, or, solution: please add information like this to your original post.

Also, you need to post example code that is "stripped down" to illustrate the key problem you are having here; my guess is that no one is going to take the time to read this massive "dump" of code, and figure out what's going on.

There are several valid ways to create dynamic sharing of data, Events, Controls, etc. between any number of Windows Forms (using MDI, or not using MDI). Help us bring your issue into "clear focus," and I, and I am sure other people here, will be happy to assist you.

yours, Bill

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