C#.NET,谁能帮我谢谢注释,数据库连接方面我乱了,超感谢!!!
publicvoidPX(stringPXName,stringPXType){//查询员工信息GridView1.DataSourceID="";stringstrSq...
public void PX(string PXName, string PXType)
{
//查询员工信息
GridView1.DataSourceID = "";
string strSqlText = @"SELECT * FROM emplove_List WHERE " + PXType + " ='" + PXName + "'";
SqlConnection sqlconn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);
sqlconn.Open();
SqlDataAdapter sda = new SqlDataAdapter(strSqlText, sqlconn);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
sda.Dispose();
ds.Dispose();
sqlconn.Close();
if (GridView1.Rows.Count == 0)
{
nullla.Visible = true;
}
else
{
nullla.Visible = false;
}
} 展开
{
//查询员工信息
GridView1.DataSourceID = "";
string strSqlText = @"SELECT * FROM emplove_List WHERE " + PXType + " ='" + PXName + "'";
SqlConnection sqlconn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString);
sqlconn.Open();
SqlDataAdapter sda = new SqlDataAdapter(strSqlText, sqlconn);
DataSet ds = new DataSet();
sda.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
sda.Dispose();
ds.Dispose();
sqlconn.Close();
if (GridView1.Rows.Count == 0)
{
nullla.Visible = true;
}
else
{
nullla.Visible = false;
}
} 展开
2个回答
展开全部
public void PX(string PXName, string PXType)
{
//查询员工信息
GridView1.DataSourceID = ""; //给控件GridView设置DataSourceID
string strSqlText = @"SELECT * FROM emplove_List WHERE " + PXType + " ='" + PXName + "'"; //SQL查询语句
SqlConnection sqlconn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString); //从web.config文件中读取访问字符串,建立数据库访问
sqlconn.Open(); //打开访问
SqlDataAdapter sda = new SqlDataAdapter(strSqlText, sqlconn); //根据SQL语句和打开的数据库,进行查询,并将结果放到数据适配器中
DataSet ds = new DataSet(); //新建一个表
sda.Fill(ds); //填充新建的表
GridView1.DataSource = ds; //把控件GridView的数据源设置为填充过的数据表
GridView1.DataBind(); //执行数据绑定
sda.Dispose(); //释放数据适配器
ds.Dispose(); //释放数据表
sqlconn.Close(); //关闭数据库连接
if (GridView1.Rows.Count == 0) //判断,如果GridView的行数为0
{
nullla.Visible = true; //不可见
}
else
{
nullla.Visible = false; //可见
}
}
{
//查询员工信息
GridView1.DataSourceID = ""; //给控件GridView设置DataSourceID
string strSqlText = @"SELECT * FROM emplove_List WHERE " + PXType + " ='" + PXName + "'"; //SQL查询语句
SqlConnection sqlconn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString); //从web.config文件中读取访问字符串,建立数据库访问
sqlconn.Open(); //打开访问
SqlDataAdapter sda = new SqlDataAdapter(strSqlText, sqlconn); //根据SQL语句和打开的数据库,进行查询,并将结果放到数据适配器中
DataSet ds = new DataSet(); //新建一个表
sda.Fill(ds); //填充新建的表
GridView1.DataSource = ds; //把控件GridView的数据源设置为填充过的数据表
GridView1.DataBind(); //执行数据绑定
sda.Dispose(); //释放数据适配器
ds.Dispose(); //释放数据表
sqlconn.Close(); //关闭数据库连接
if (GridView1.Rows.Count == 0) //判断,如果GridView的行数为0
{
nullla.Visible = true; //不可见
}
else
{
nullla.Visible = false; //可见
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询