怎样在C#的Gridview控件中对数据库中的文件进行更新、增添、删除?
2个回答
展开全部
配置数据源时 选择高级 然后选择更新、增添、删除 就行了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以仿照如下代码:
protected void RowUpdata(object sender, GridViewUpdateEventArgs e)
{
string sqlstr = "update film set filename='" + ((TextBox)(sms_grade.Rows[e.RowIndex].Cells[0].Controls[1])).Text.ToString().Trim() +
"',filecount='"+((TextBox)(sms_grade.Rows[e.RowIndex].Cells[1].Controls[1])).Text.ToString().Trim() +
"',Actor1='"+((TextBox)(sms_grade.Rows[e.RowIndex].Cells[2].Controls[1])).Text.ToString().Trim() +
"',Actor2='"+((TextBox)(sms_grade.Rows[e.RowIndex].Cells[3].Controls[1])).Text.ToString().Trim() +
"' where filename='" + name +"'";
SqlCommand sqlcom = new SqlCommand(sqlstr, sms_conn);
sms_conn.Open();
sqlcom.ExecuteNonQuery();
sms_grade.EditIndex = -1;
SMS_BindGrid();
sms_conn.Close();
}
protected void RowEditing(object sender, GridViewEditEventArgs e)
{
name = ((Label)sms_grade.Rows[e.NewEditIndex].FindControl("Labelname")).Text;
sms_grade.EditIndex = e.NewEditIndex;
SMS_BindGrid();
}
protected void RowCancel(object sender, GridViewCancelEditEventArgs e)
{
sms_grade.EditIndex = -1;
SMS_BindGrid();
}
protected void RowUpdata(object sender, GridViewUpdateEventArgs e)
{
string sqlstr = "update film set filename='" + ((TextBox)(sms_grade.Rows[e.RowIndex].Cells[0].Controls[1])).Text.ToString().Trim() +
"',filecount='"+((TextBox)(sms_grade.Rows[e.RowIndex].Cells[1].Controls[1])).Text.ToString().Trim() +
"',Actor1='"+((TextBox)(sms_grade.Rows[e.RowIndex].Cells[2].Controls[1])).Text.ToString().Trim() +
"',Actor2='"+((TextBox)(sms_grade.Rows[e.RowIndex].Cells[3].Controls[1])).Text.ToString().Trim() +
"' where filename='" + name +"'";
SqlCommand sqlcom = new SqlCommand(sqlstr, sms_conn);
sms_conn.Open();
sqlcom.ExecuteNonQuery();
sms_grade.EditIndex = -1;
SMS_BindGrid();
sms_conn.Close();
}
protected void RowEditing(object sender, GridViewEditEventArgs e)
{
name = ((Label)sms_grade.Rows[e.NewEditIndex].FindControl("Labelname")).Text;
sms_grade.EditIndex = e.NewEditIndex;
SMS_BindGrid();
}
protected void RowCancel(object sender, GridViewCancelEditEventArgs e)
{
sms_grade.EditIndex = -1;
SMS_BindGrid();
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询