ASP.NET中删除主题的代码。大虾们,最近小弟特别喜欢研究C#代码,哪位能帮小弟解释一下这段代码,谢谢啦
protectedvoidgvInfo_RowDeleting(objectsender,GridViewDeleteEventArgse){SqlHelpermydat...
protected void gvInfo_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
SqlHelper mydata = new SqlHelper();
string ID = gvInfo.DataKeys[e.RowIndex].Values[0].ToString();
try
{
mydata.RunSql("delete from Topic where id='" + ID + "'");
Label4.Text = "删除成功!";
gvInfo.EditIndex = -1;
GetDate();
}
catch
{ Label4.Text = "删除失败!"; }
}
private void GetDate()
{
try
{ gvInfo.DataSource = GetCodeBy(0);
gvInfo.DataBind();
}
catch
{ }
}
protected void gvInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvInfo.PageIndex = e.NewPageIndex;
GetDate();
}
public DataSet GetCodeBy(int iCount)
{
SqlHelper date = new SqlHelper();
string strTop = "";
if (iCount > 1)
{ strTop = "top " + iCount.ToString(); }
string sql = "select " + strTop + " * from [Topic] ";
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;
}
} 展开
{
SqlHelper mydata = new SqlHelper();
string ID = gvInfo.DataKeys[e.RowIndex].Values[0].ToString();
try
{
mydata.RunSql("delete from Topic where id='" + ID + "'");
Label4.Text = "删除成功!";
gvInfo.EditIndex = -1;
GetDate();
}
catch
{ Label4.Text = "删除失败!"; }
}
private void GetDate()
{
try
{ gvInfo.DataSource = GetCodeBy(0);
gvInfo.DataBind();
}
catch
{ }
}
protected void gvInfo_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvInfo.PageIndex = e.NewPageIndex;
GetDate();
}
public DataSet GetCodeBy(int iCount)
{
SqlHelper date = new SqlHelper();
string strTop = "";
if (iCount > 1)
{ strTop = "top " + iCount.ToString(); }
string sql = "select " + strTop + " * from [Topic] ";
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;
}
} 展开
展开全部
string ID = gvInfo.DataKeys[e.RowIndex].Values[0].ToString(); 拿到当前行索引ID
try
{
mydata.RunSql("delete from Topic where id='" + ID + "'");调用方法 输入SQL命令删除数据表拿到的ID列
Label4.Text = "删除成功!";提示信息
gvInfo.EditIndex = -1;改变索引?
GetDate();
}
private void GetDate()
{
try
{
gvInfo.DataSource = GetCodeBy(0); 调用GetCodeBy()方法 传参额 0
gvInfo.DataBind();
}
catch
{ }
}
public DataSet GetCodeBy(int iCount) 这个方法是拿到数据表的
你的代码不全啊 调用的方法都看不到 就这样 给分吧
try
{
mydata.RunSql("delete from Topic where id='" + ID + "'");调用方法 输入SQL命令删除数据表拿到的ID列
Label4.Text = "删除成功!";提示信息
gvInfo.EditIndex = -1;改变索引?
GetDate();
}
private void GetDate()
{
try
{
gvInfo.DataSource = GetCodeBy(0); 调用GetCodeBy()方法 传参额 0
gvInfo.DataBind();
}
catch
{ }
}
public DataSet GetCodeBy(int iCount) 这个方法是拿到数据表的
你的代码不全啊 调用的方法都看不到 就这样 给分吧
追问
大虾,我把剩下的代码发出来了,求解啊
追答
//这个代码是用来访问数据库 并返回一个数据表的
public DataSet GetCodeBy(int iCount)
{
SqlHelper date = new SqlHelper();
string strTop = "";
if (iCount > 1) //当传参参数大于1时 执行 本代码中传参为0 故下面语句不执行
{ strTop = "top " + iCount.ToString(); }
string sql = "select " + strTop + " * from [Topic] ";
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;返回Dataset
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询