问题描述
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;
//将命令分配给适配器
SqlDataAdapter objSQLDataAdapter = new SqlDataAdapter(objSQLCommand);
objSQLDataAdapter.Fill(dsData);
GrdViewPatientDiagnosisDetails.DataSource = dsData.Tables [0];
GrdViewPatientDiagnosisDetails.DataBind();
objSQLConnection.Close();
我试图在点击按钮(View)时查看GRID。它不起作用。请建议我应该这样做吗?
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?
推荐答案
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";
}
}
这篇关于单击按钮上的GridView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!