Click here to Skip to main content
15,880,651 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
private void frmpatient_Load(object sender, EventArgs e)
        {
            con = new MySqlConnection();
            con = dbcon.openconnection();

            showdatabase();
        }


C#
public void showdatabase() {

          con.Open();
          ds = new DataSet();
          cmd = new MySqlCommand();
          cmd.Connection = con;
          cmd.CommandText = "SELECT * FROM `Ptient`";
          da = new MySqlDataAdapter(cmd);
          da.Fill(ds, "st");
          dataGridViewpatient.DataSource = ds;
          dataGridViewpatient.DataMember = "st";

          con.Close();
      }
Posted
Updated 20-Mar-14 19:27pm
v2
Comments
V5709 21-Mar-14 1:51am    
Have you checked that data is coming in ds or not?
Marcin Kozub 21-Mar-14 5:23am    
1. I think that should be 'Patient' instead of 'Ptient' in your SQL query.
2. What is dbcon?
zakirox123 21-Mar-14 14:18pm    
hi dude my table name is same as this my spelling mistakes ;)

C#
private void frmpatient_Load(object sender, EventArgs e)
{
if (!(IsPostBack))
      {
con = new MySqlConnection();
con = dbcon.openconnection();

showdatabase();
}
}




Check IsPostBack Property.
 
Share this answer
 
Hi every one i am sorry its my mistake i have created the connection already in a separate class and again i have been coded new Mysqlconnection :D that's my mistake any how i sought out the problem

//database connection
C#
MySqlConnection con;
dbconnection dbcon = new dbconnection();


MySqlDataAdapter da;
DataSet ds;

public frmpatient()
{
    InitializeComponent();
}

private void frmpatient_Load(object sender, EventArgs e)
{


    showdatabase();
}

public void showdatabase() {

    con = dbcon.openconnection();
    con.Open();
    MessageBox.Show("Connection ok");
    da = new MySqlDataAdapter("select * from actor",con);
    ds = new DataSet();
    da.Fill(ds);
    dataGridViewpatient.DataSource = ds.Tables[0];
    con.Close();


}
 
Share this answer
 

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