int j = 1;
string[] Samebh = new string[256];
Samebh[j] = dr[i]["编号"].ToString();
j = j + 1;
Response.Write("<script>alert('重复的内容');location='LinkExcel.aspx'</script></script> ");我想把这个数组Samebh的所有数据用Response.Write显示出来,该怎么做?也就是实现MessageBox.show(Samebh.Lengh)的功能,由于在web中不能使用,所以只能使用Response.Write()来实现了。
各位帮帮忙,多谢。

解决方案 »

  1.   


    Samebh[j] = dr[i]["编号"].ToString();dr是什么??
      

  2.   

    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "jstext","<script>alert('重复的内容');location='LinkExcel.aspx'</script></script> ");就行了
      

  3.   

    哦,那就这样...
    DataTable dr = XXX();
    int j = 1;
    int length = dr.Rows.Count;
    string[] Samebh = new string[length];
    foreach(DataRowView drv in dr)
    {
       Samebh[j] = drv["编号"].ToString();
        j = j + 1;
    }
    for(int i=0;i<Samebh.Length;i++)
    {
         //输出数组中的所有值
        Response.Write(Samebh[i]+"<br/>");
    }
    ...
      

  4.   

    接上:输出数组的长度:Response.Write("<script>alert('"+Samebh.Length+"');</script>");
    跳转:ClientScript.RegisterClientScriptBlock(GetType(), "", "<script>alert('重复的内容!');setTimeout(function(){location.href='LinkExcel.aspx'},100);</script>");
      

  5.   

      //把Excel表格里的数据插入SQL
            DataRow[] dr = dt.Select();//定义一个DataRow数组
            int rowsnum = dt.Rows.Count;
            if (rowsnum == 0)
            {
                Response.Write("<script>alert('Excel表为空表,无数据!')</script>");//当Excel表为空时,对用户进行提示
            }
            else
            {
                for (int i = 0; i < dr.Length; i++)
                {
                    string rq = dr[i]["日期"].ToString();//日期 excel列名
                    string bh = dr[i]["编号"].ToString();
                    string xm = dr[i]["姓名"].ToString();
                    string dx = dr[i]["底薪"].ToString();
                    string kh = dr[i]["考核"].ToString();
                    string jl = dr[i]["奖励"].ToString();
                    string sqlcheck = "select count(*) from test where bh='" + bh + "'";//检查用户是否存在(查询的标准为是否有相同的“编号”存在)
                    SqlCommand sqlcmd = new SqlCommand(sqlcheck,cn);
                    int count = Convert.ToInt32(sqlcmd.ExecuteScalar());
                    if (count < 1)
                    {
                        string insert = "insert into test values('" + rq + "','" + bh + "','" + xm + "','" + dx + "','" + kh + "','" + jl + "')";                    SqlCommand cmd = new SqlCommand(insert, cn);
                        try
                        {
                            cmd.ExecuteNonQuery();
                            //BindGridView();
                        }
                        catch (MembershipCreateUserException ex)//捕捉异常
                        {
                            Response.Write("<script>alert('导入内容:" + ex.Message + "')</script>");
                        }
                    }
                    else
                    {
                        int j = 1;
                        string[] Samebh = new string[dr.Length];
                        foreach (DataRowView drv in dr)
                        {
                            Samebh[j] = drv["编号"].ToString();
                            j = j + 1;
                        }
                        //Response.Write("<script>alert('禁止重复导入数据!');location='LinkExcel.aspx'</script>");
                        //continue; 
                        for (int k = 1; k < Samebh.Length; k++)
                        {
                            //输出数组中的所有值
                            Response.Write("<script>alert('" + Samebh[j] + "');location='LinkExcel.aspx'</script>");
                        }
                    }
                }            Response.Write("<script>alert('Excle表导入成功!');location='LinkExcel.aspx'</script>");
            }
    无敌筒子,我用你提供的法子试了一下,出错了:无法将类型“System.Data.DataRow”转换为“System.Data.DataRowView”;
    后来我用for语句替代foreach做了一个循环,输出是对了,但是只有导出了数组中的一个数据,excel表中有2条数据是重复的,有2条数据存在里面才对,但是我调的时候发现只存了第一条重复的“编号”。请指教,谢谢。
      

  6.   

    else
            {
                int j = 0;
                string[] Samebh = new string[dr.Length];
                for (int i = 0; i < dr.Length; i++)
                {
                    string rq = dr[i]["日期"].ToString();//日期 excel列名
                    string bh = dr[i]["编号"].ToString();
                    string xm = dr[i]["姓名"].ToString();
                    string dx = dr[i]["底薪"].ToString();
                    string kh = dr[i]["考核"].ToString();
                    string jl = dr[i]["奖励"].ToString();
                    string sqlcheck = "select count(*) from test where bh='" + bh + "'";//检查用户是否存在(查询的标准为是否有相同的“编号”存在)
                    SqlCommand sqlcmd = new SqlCommand(sqlcheck,cn);
                    int count = Convert.ToInt32(sqlcmd.ExecuteScalar());
                    if (count < 1)
                    {
                        string insert = "insert into test values('" + rq + "','" + bh + "','" + xm + "','" + dx + "','" + kh + "','" + jl + "')";                    SqlCommand cmd = new SqlCommand(insert, cn);
                        try
                        {
                            cmd.ExecuteNonQuery();
                            //BindGridView();
                        }
                        catch (MembershipCreateUserException ex)//捕捉异常
                        {
                            Response.Write("<script>alert('导入内容:" + ex.Message + "')</script>");
                        }
                    }
                    else
                    {
                        Samebh[j] = dr[i]["编号"].ToString();
                        j = j + 1;
                        //Response.Write("<script>alert('禁止重复导入数据!');location='LinkExcel.aspx'</script>");
                        //continue; 
                        for (int k = 0; k < Samebh.Length; k++)
                        {
                             //输出数组中的所有值
                             Response.Write("<script>alert('" + Samebh[k] + "');location='LinkExcel.aspx'</script>");
                        }
                    }
                }            Response.Write("<script>alert('Excle表导入成功!');location='LinkExcel.aspx'</script>");
            }
    这个我已经跑出来了数组里存的就是重复记录的“编号”,但是读不出来,读出来的只有其中的一个。这是咋回事啊?