C# 从数据库表中删除所有行时,GridView不显示

C# 从数据库表中删除所有行时,GridView不显示,c#,mysql,asp.net,gridview,C#,Mysql,Asp.net,Gridview,我面临一个问题,不知道如何设置这个问题的问题是,我的项目工作良好,但当我删除sql数据库中的所有行时,它没有显示帮助 非常感谢您的回复 这是我的密码 public partial class Web_grid : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) {

我面临一个问题,不知道如何设置这个问题的问题是,我的项目工作良好,但当我删除sql数据库中的所有行时,它没有显示帮助 非常感谢您的回复

这是我的密码

public partial class Web_grid : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {


            if (!IsPostBack)
            {

            BindData();


        }
    }

protected void BindData()
        {
            SqlConnection conne = new SqlConnection("Data Source=192.168.0.6;Initial Catalog=TestDataBase;Persist Security Info=True;User ID=sa;Password=malick");

            DataSet ds = new DataSet();

            conne.Open();

            string cmdstr = "SELECT * FROM OPR1 ";

            SqlCommand cmd = new SqlCommand(cmdstr, conne);

            SqlDataAdapter adp = new SqlDataAdapter(cmd);

            adp.Fill(ds);

            cmd.ExecuteNonQuery();

            conne.Close();
            GridView1.DataSource = ds;
            GridView1.DataBind();
         //   GridView1.DataSource =null;

           // GridView1.DataSource = ds;
          //  GridView1.DataBind();
            //ds = null;
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            SqlConnection conne = new SqlConnection("Data Source=192.168.0.6;Initial Catalog=TestDataBase;Persist Security Info=True;User ID=sa;Password=malick");

            conne.Open();

            if (e.CommandName.Equals("ADD"))
            {

                Calendar txtOpenDate = (Calendar)GridView1.FooterRow.FindControl("txtOpenDate");

                TextBox txtCloseDate = (TextBox)GridView1.FooterRow.FindControl("txtCloseDate");

                DropDownList DropDownListoppr = (DropDownList)GridView1.FooterRow.FindControl("DropDownListoppr");

                DropDownList DropDownListStages = (DropDownList)GridView1.FooterRow.FindControl("DropDownListStages");

                TextBox txtAddLine = (TextBox)GridView1.FooterRow.FindControl("txtAddLine");

                TextBox txtStages = (TextBox)GridView1.FooterRow.FindControl("txtStages");

                TextBox txtAddOppId = (TextBox)GridView1.FooterRow.FindControl("txtAddOppId");




                string cmdstr = "insert into OPR1(OpenDate,CloseDate,SlpCode,Step_Id,Line,OpprId) values(@txtOpenDate,@txtCloseDate,@SlpCode,@Step_Id,@txtAddLine,@txtAddOppId)";

                SqlCommand cmd = new SqlCommand(cmdstr, conne);

                cmd.Parameters.AddWithValue("@txtOpenDate", txtOpenDate.TodaysDate);

                cmd.Parameters.AddWithValue("@txtCloseDate", txtCloseDate.Text);


                cmd.Parameters.AddWithValue("@Step_Id", DropDownListStages.SelectedValue.ToString()); // SelectedItem.ToString());

                cmd.Parameters.AddWithValue("@SlpCode", DropDownListoppr.SelectedValue.ToString()); // SelectedItem.ToString());

                cmd.Parameters.AddWithValue("@txtStages", txtStages.Text);

                cmd.Parameters.AddWithValue("@txtAddLine", txtAddLine.Text);

                cmd.Parameters.AddWithValue("@txtAddOppId", txtAddOppId.Text);

                cmd.ExecuteNonQuery();
             //   this.TextBox1.Text = DropDownList1.SelectedItem.ToString();
           //     this.TextBox3.Text = DropDownList1.SelectedValue.ToString();


                BindData();
                conne.Close();
            }

        }
        protected void GridView1_OnRowDataBound(object sender, GridViewRowEventArgs e)
        {

            if (e.Row.RowType == DataControlRowType.Footer)
            {

                DropDownList DropDownListoppr = (DropDownList)e.Row.FindControl("DropDownListoppr");
                DropDownList DropDownListStages = (DropDownList)e.Row.FindControl("DropDownListStages");

                DataTable CardCode = new DataTable();
                DataTable CardCode1 = new DataTable();

                SqlConnection connection = new SqlConnection("Data Source=192.168.0.6;Initial Catalog=TestDataBase;Persist Security Info=True;User ID=sa;Password=malick");
                using (connection)
                {



                    SqlCommand theCommand = new SqlCommand("select SlpCode,SlpName from OSLP ", connection);
                    SqlCommand theCommand1 = new SqlCommand("select Distinct StepId, Descript from OOST ", connection);
                    SqlDataAdapter adapter = new SqlDataAdapter(theCommand);
                    SqlDataAdapter adapter1 = new SqlDataAdapter(theCommand1);

                    adapter.Fill(CardCode);
                    adapter1.Fill(CardCode1);
                    //DropDownList7.DataSource = CardCode;
                    //DropDownList7.DataTextField = "SlpName";
                    //DropDownList7.DataValueField = "SlpCode";
                    //DropDownList7.DataBind();

                    if (CardCode.Rows.Count > 0)
                    {
                        for (int i = 0; i < CardCode.Rows.Count; i++)
                        {
                            string name3 = CardCode.Rows[i]["SlpName"].ToString();
                            string slpCode = CardCode.Rows[i]["SlpCode"].ToString();
                            DropDownListoppr.Items.Add(new ListItem(name3, slpCode));



                        }
                    }

                    if (CardCode1.Rows.Count > 0)
                    {
                        for (int j = 0; j < CardCode1.Rows.Count; j++)
                        {
                            string name4 = CardCode1.Rows[j]["Descript"].ToString();
                            string stageCode = CardCode1.Rows[j]["StepId"].ToString();
                            DropDownListStages.Items.Add(new ListItem(name4, stageCode));
                        }
                    }
                }
            }
        }
公共部分类Web\u网格:System.Web.UI.Page
{
受保护的无效页面加载(对象发送方、事件参数e)
{
如果(!IsPostBack)
{
BindData();
}
}
受保护的void BindData()
{
SqlConnection-conne=newsqlconnection(“数据源=192.168.0.6;初始目录=TestDataBase;持久安全信息=True;用户ID=sa;密码=malick”);
数据集ds=新数据集();
conne.Open();
string cmdstr=“从OPR1中选择*”;
SqlCommand cmd=新的SqlCommand(cmdstr,conne);
SqlDataAdapter adp=新的SqlDataAdapter(cmd);
自动进料(ds);
cmd.ExecuteNonQuery();
conne.Close();
GridView1.DataSource=ds;
GridView1.DataBind();
//GridView1.DataSource=null;
//GridView1.DataSource=ds;
//GridView1.DataBind();
//ds=null;
}
受保护的void GridView1_row命令(对象发送方,GridViewCommandEventArgs e)
{
SqlConnection-conne=newsqlconnection(“数据源=192.168.0.6;初始目录=TestDataBase;持久安全信息=True;用户ID=sa;密码=malick”);
conne.Open();
如果(如CommandName.Equals(“ADD”))
{
Calendar txtOpenDate=(Calendar)GridView1.FooterRow.FindControl(“txtOpenDate”);
TextBox txtCloseDate=(TextBox)GridView1.FooterRow.FindControl(“txtCloseDate”);
DropDownList dropdownlistropr=(DropDownList)GridView1.FooterRow.FindControl(“dropdownlistropr”);
DropDownList DropDownListStages=(DropDownList)GridView1.FooterRow.FindControl(“DropDownListStages”);
TextBox txtAddLine=(TextBox)GridView1.FooterRow.FindControl(“txtAddLine”);
TextBox txtStages=(TextBox)GridView1.FooterRow.FindControl(“txtStages”);
TextBox txtAddOppId=(TextBox)GridView1.FooterRow.FindControl(“txtAddOppId”);
string cmdstr=“插入OPR1(OpenDate、CloseDate、SlpCode、Step_Id、Line、OpprId)值(@txtOpenDate、@txtCloseDate、@SlpCode、@Step_Id、@txtAddLine、@txtAddOppId)”;
SqlCommand cmd=新的SqlCommand(cmdstr,conne);
cmd.Parameters.AddWithValue(“@txtOpenDate”,txtOpenDate.TodaysDate);
cmd.Parameters.AddWithValue(“txtCloseDate”,txtCloseDate.Text);
cmd.Parameters.AddWithValue(“@Step_Id”,DropDownListStages.SelectedValue.ToString());//SelectedItem.ToString());
cmd.Parameters.AddWithValue(“@SlpCode”,dropdownlistopr.SelectedValue.ToString());//SelectedItem.ToString());
cmd.Parameters.AddWithValue(“@txtStages”,txtStages.Text);
cmd.Parameters.AddWithValue(“@txtAddLine”,txtAddLine.Text);
cmd.Parameters.AddWithValue(“@txtAddOppId”,txtAddOppId.Text);
cmd.ExecuteNonQuery();
//this.TextBox1.Text=DropDownList1.SelectedItem.ToString();
//this.TextBox3.Text=DropDownList1.SelectedValue.ToString();
BindData();
conne.Close();
}
}
受保护的void GridView1_OnRowDataBound(对象发送方,GridViewRowEventArgs e)
{
if(e.Row.RowType==DataControlRowType.Footer)
{
DropDownList dropdownlistropr=(DropDownList)e.Row.FindControl(“dropdownlistropr”);
DropDownList DropDownListStages=(DropDownList)e.Row.FindControl(“DropDownListStages”);
DataTable CardCode=新DataTable();
DataTable CardCode1=新DataTable();
SqlConnection=newsqlconnection(“数据源=192.168.0.6;初始目录=TestDataBase;持久安全信息=True;用户ID=sa;密码=malick”);
使用(连接)
{
SqlCommand theCommand=newsqlcommand(“从OSLP中选择SlpCode、SlpName”,连接);
SqlCommand theCommand1=新的SqlCommand(“选择不同的StepId,从OOST中描述”,连接);
SqlDataAdapter=新的SqlDataAdapter(命令);
SqlDataAdapter adapter1=新的SqlDataAdapter(命令1);
适配器。填充(CardCode);
适配器1.填充(卡片代码1);
//DropDownList7.DataSource=CardCode;
//DropDownList7.DataTextField=“SlpName”;
//DropDownList7.DataValueField=“SlpCode”;
//DropDownList7.DataBind();
如果(CardCode.Rows.Count>0)
{
对于(int i=0;i0)
{
对于(int j=0;j
在BindData方法中不需要cmd.ExecuteNonQuery();如下所示