最近做一个页面遇到从一个text框中一次获取多值参数的问题(如:一次可输入多个学生ID),点击查看后以表格形式返回查询结果! 
我在公共类里这样建立方法: 
private static readonly string sqlcommandstr = @"Select *From dbo.stu Inner Join dbo.stuScore on stu.Id=stuScore.Id Where stu.Id  IN (@Id)) Order by stuScore.Score";     public static DataTable GetDateTable(string Id) 
    {        
        using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ToString())) 
        { 
            using (SqlCommand command = new SqlCommand(sqlcommandstr, connection)) 
            { 
                command.Parameters.AddWithValue("@Id",Id);                 connection.Open();                 SqlDataAdapter sda = new SqlDataAdapter(sqlcommandstr, connection);                 DataTable dt = new DataTable();                 sda.Fill(dt);                 return dt;                 connection.Close(); 
            } 
        }     } 
该页面中的相关代码我是这样写的: private string stuIdsParameter 
    { 
        get 
        { 
            string stuIds = String.Empty;             int output, stuCount = 0;             StringReader reader = new StringReader(stuIdTextBox.Text);             string line = reader.ReadLine();             string nextline = reader.ReadLine();             while (nextline != null) 
            { 
                if (Int32.TryParse(nextline, out output)) 
                { 
                    if (Int32.TryParse(line, out output)) 
                    { 
                        stuIds += String.Format("{0},", line);                         srCount++; 
                    } 
                    line = nextline; 
                } 
                nextline = reader.ReadLine(); 
            } 
            if (Int32.TryParse(line, out output)) 
            { 
                stuIds += line;                 srCount++; 
            } 
            return stuIds; 
        } 
    } 
      protected void viewButton_Click(object sender, ClickEventArgs e) 
    { 
        
        string StuId = this.stuIdsParameter;         DataTable dt = DataAccess.GetDateTable(StuId);         CasesGridView.DataSource = dt;         CasesGridView.DataBind();  
    } 
执行结果显示参数有错(数据库中stuid使用的是bigint型,错误信息为:转换出错,不知怎么解决?),有哪位高手帮忙看看!小弟不胜感激!

解决方案 »

  1.   

    想办法在java方法中把输入的stuid转换成bigint型,然后进行查询阿
      

  2.   

    string StuId = this.stuIdsParameter;你先看看这个StuId的值获得的是什么吧Select *From dbo.stu Inner Join dbo.stuScore on stu.Id=stuScore.Id Where stu.Id  IN (@Id)) Order by stuScore.Score还有,红色部分多一个)
      

  3.   

    我不是高手,但你的问题很明显的啊?你把数据库里的stuid改成char型或把 public static DataTable GetDateTable(string Id) 
    这里的 Id类型转化一下不就是行了?
      

  4.   

    我不是高手,但你的问题很明显的啊?你把数据库里的stuid改成char型或把 public static DataTable GetDateTable(string Id) 
    这里的 Id类型转化一下不就是行了?
      

  5.   

    谢谢各位!错误信息:Error converting data type varchar to bigint.
      

  6.   

    谢谢回复!
    1、string StuId = this.stuIdsParameter;获取的是多个stuId参数值;起初我是把所有代码都放在该页面的后台代码中,没有写入公共类;程序能成功运行;
    2、多出的)是我上传代码时修改出错了,不是这方面问题;
    仍然十分感谢回复!期望更多高手帮忙解决!
      

  7.   

    谢谢!首先该数据库是不行的,因为还有很多页面都用到该字段!其次,是一次输入多个ID进行查询,转换成bigint肯定不行!