public static bool execSQL(string[] str,string ip)
    {
        SqlConnection con = zxpxDB.createcon();
        con.Open();
        SqlCommand com = new SqlCommand();
        com.Connection = con;
        com.Parameters.Add("@id", SqlDbType.Int);
        com.Parameters.Add("@ip", SqlDbType.NVarChar,100);
        com.Parameters.Add("@name", SqlDbType.NVarChar, 200);
        try
        {
            com.CommandText = "pr_text";
            com.CommandType=CommandType.StoredProcedure;
            foreach (string s in str)
            {
                com.Parameters[0].Value = s;
                com.Parameters[1].Value = ip;
                com.Parameters[2].Value = str;                
                com.ExecuteNonQuery();
            }
            com.Dispose();
            con.Close();
        }
        catch (Exception e)
        {
            con.Close();
            return false;
        }
        return true;
    }

解决方案 »

  1.   

    com.Parameters[2].Value = str[i]
      

  2.   

    com.Parameters[2].Value只是一个单一的值,比如说:“123”,false,true等等,而你的str却是一个数组,怎么可能不错。
      

  3.   

    str是个数组
    你给的参数是字符串
      

  4.   

    com.Parameters[2].Value = str; 必须报错
    com.Parameters[2].Value这个返回的是string  而str是数组  一个是原始数据类型 一个基本数据类型 肯定错啊
      

  5.   

    建议LZ这样做
    for(int i=0;i<str.lengthli++)
    {
        xxx=str[i];
    }
      

  6.   

    正确转换就是
    com.Parameters[2].Value = str[下标];
      

  7.   

    com.Parameters[2].Value = s; 
      

  8.   

    晕。你知道 string[]  和  string的区别吗??
      

  9.   

    数组 字符串要全部数组com.Parameters[2].Value = str[',']; 对吗?
      

  10.   

    com.Parameters[2].Value = str[','];  //这个是 什么意思?
      

  11.   


      foreach (string s in str)
      {
      com.Parameters[0].Value = s;
      com.Parameters[1].Value = ip;
      com.Parameters[2].Value = str;   
      com.ExecuteNonQuery();
      }
    改为
                string strAll = "";
                foreach (string s in str)
                {
                    strAll += s;
                }
                foreach (string s in str)
                {
                   com.Parameters[0].Value = s;
                   com.Parameters[1].Value = ip;
                   com.Parameters[2].Value = strAll;   
                   com.ExecuteNonQuery();
                }
      

  12.   

    com.Parameters[2].Value = str;   
    改为:
    com.Parameters[2].Value = str.Aggregate((a,b)=>a+b);