Click here to Skip to main content
15,906,645 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
DataSet dsData = new DataSet();

SqlConnection objSQLConnection=null;


string ConnectionString = "Data Source=INGNRGPILPSQL01;Initial Catalog=AHD20_A103_Group2_DB;";

objSQLConnection = new SqlConnection(ConnectionString);

objSQLConnection.Open();

SqlCommand objSQLCommand = new SqlCommand("usp_ViewPatientDiagnosisFOM", objSQLConnection);
objSQLCommand.CommandType = System.Data.CommandType.StoredProcedure;

// Assign command to adaptor
SqlDataAdapter objSQLDataAdapter = new SqlDataAdapter(objSQLCommand);



objSQLDataAdapter.Fill(dsData);

GrdViewPatientDiagnosisDetails.DataSource = dsData.Tables[0];

GrdViewPatientDiagnosisDetails.DataBind();

objSQLConnection.Close();

I am trying to view a GRID on clicking a button(View). It is not working. Please suggest hw should i do it right?
Posted

First check DataTable has any row or not
if Row.Count() > 0
then set AutoGeneratedColumn property is True then check it.
 
Share this answer
 
C#
protected void Button1_Click(object sender, EventArgs e)
    {

 SqlDataAdapter da = new SqlDataAdapter("select * from empupload", sqlconn);
        DataSet ds = new DataSet();
        da.Fill(ds);
        if (ds.Tables[0].Rows.Count>0)
        {

            GridView1.DataSource = ds;
            GridView1.DataBind();
            
            Label2.Visible = false;
        }
        
        
        //}
        else
        {

            Label2.Visible = true;
            Label2.Text = "No Records To Display";
           

        }
}
 
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