protected void Page_Load(object sender, EventArgs e)
        {
            Label1.Text = Session["user"].ToString();
        }        protected void btnLy_Click(object sender, EventArgs e)
        {
            BLL.Lybook ly = new BLL.Lybook();
            Model.LybookInfo info = new Model.LybookInfo();
            info.Content = Request.Form["S1"];
            info.Time = System.DateTime.Now.ToString();
            info.UserId = Label1.Text;
            if (ly.InsertMessage(info) != false)
            {
                labLy.Text = "留言成功!";
            }
            else
                labLy.Text = "ERROR";
info.UserId是int类型。怎么让Label1.text的内容传进数据库UserId中,本来是想改数据库UserId的类型。。但是不能改。。请高人说的详细点,本人新手。。

解决方案 »

  1.   

    ADO.NET
    String Sql="insert into tablename (fields) (@fields)";
    Cmd.Parmets.AddWithValue("@fields",(object).Tostring());
      

  2.   

    另外你那个
    我看了不是传进数据库问题
    只是类型转换
    try
    {
    info.UserId =Conver.Toint( Label1.Text);}
    catch
    {
     throw new Exepction("类型错误")
    }
      

  3.   

    info.UserId = Convert.ToInt32(Label1.Text);
      

  4.   

    int.Parse和Convert.ToInt32都不行。。他说无法将类型INT隐式转换为String。
      

  5.   

    可能Label1.Text中的数据含有子母、符号或者汉字其中一个字符。必须保证Label1.Text中的全部是数字,否则无法转换成整型。