早教吧作业答案频道 -->其他-->
感觉就是GridView数据绑定,但这个代码不是特别看到懂,不懂的我在下面有注释,privatevoidGetInfo(){try{gvInfo.DataSource=GetCodeBy(0);//为什么GetCodeBy(0);要默认给0?gvInfo.DataBind();}catch{}}publicDataSetGetCod
题目详情
感觉就是GridView数据绑定,但这个代码不是特别看到懂,不懂的我在下面有注释,
private void Get_Info() {
try
{
gvInfo.DataSource = GetCodeBy(0); //为什么GetCodeBy(0);要默认给0?gvInfo.DataBind();
}
catch
{
}
}
public DataSet GetCodeBy(int iCount)//参数0传入 {
SqlHelper date = new SqlHelper();
string strTop = "";
if (iCount > 1)//iCount 参数传入是0这不是没意义了?
{
strTop = "top " + iCount.ToString(); //为什么不直接用select *全部数据绑定,要用top?
}
string sql = "select " + strTop + " * from [Clothing] "; SqlConnection con = new SqlConnection(SqlHelper.connstring);
SqlCommand cmd = new SqlCommand(sql,con);
SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = null;
try
{
con.Open();
ds = new DataSet();
da.Fill(ds);
} catch (SqlException ex)
{
throw ex;
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
}
return ds;
}
private void Get_Info() {
try
{
gvInfo.DataSource = GetCodeBy(0); //为什么GetCodeBy(0);要默认给0?gvInfo.DataBind();
}
catch
{
}
}
public DataSet GetCodeBy(int iCount)//参数0传入 {
SqlHelper date = new SqlHelper();
string strTop = "";
if (iCount > 1)//iCount 参数传入是0这不是没意义了?
{
strTop = "top " + iCount.ToString(); //为什么不直接用select *全部数据绑定,要用top?
}
string sql = "select " + strTop + " * from [Clothing] "; SqlConnection con = new SqlConnection(SqlHelper.connstring);
SqlCommand cmd = new SqlCommand(sql,con);
SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = null;
try
{
con.Open();
ds = new DataSet();
da.Fill(ds);
} catch (SqlException ex)
{
throw ex;
}
catch (Exception ex)
{
throw ex;
}
finally
{
con.Close();
}
return ds;
}
▼优质解答
答案和解析
从代码上来看,就是查询所有数据了
GetCodeBy这个方法只是没有写死,
如果其它页面用了查询前N条数据的功能的话,同样可以调用这个方法,
GetCodeBy这个方法只是没有写死,
如果其它页面用了查询前N条数据的功能的话,同样可以调用这个方法,
看了感觉就是GridView数据绑...的网友还看了以下:
已知A基因含23000个碱基对,其中一条链A:C:T:G=1:2:3:4,连续复制3次,至少需要G 2020-05-23 …
求自然拼音发音规律个别字母就算了,要说特例.比如c后接i,e,y时/s/,其它时候发/k/.g在后 2020-06-17 …
邹忌讽齐王纳谏本文在写作上主要的特点是什么?有什么好处邹忌讽齐王纳谏本文在写作上主要的特点是什么? 2020-06-18 …
我新买的葡聚糖凝胶G-75应该怎么预处理?有说直接浸泡的,还有说先用乙醇,后用水,再用盐酸.到底用 2020-06-25 …
已知某DNA分子共含有1000个碱基对,其中一条链上A:G:T:C=l:2:3:4.该DNA分子连 2020-06-26 …
要使216克吕完全燃烧要-----g氧和生成------g氧化吕 2020-07-02 …
一道大学导数题设F(x)=g(x)f(x),f(x)在x=a处连续,但不可导,又g'(a)存在,则 2020-07-15 …
配制一种药水,药与水的比例是1:50,要配置这样的药水2040g,需要()g药()g的水? 2020-12-22 …
摄影组在某大楼边拍摄武打片,要求特技演员从地面竖直飞到高处如图所示.若特技演员的质量m=50kg,人 2021-01-12 …
摄制组在某大楼边拍摄武打片,要求特技演员从地面飞到屋顶,如图所示,若特技演员的质量m=50kg(人和 2021-01-12 …