SqlConnection con = new SqlConnection(@"server=.;uid=sa;pwd=sa;database=Wish");
        SqlCommand com = new SqlCommand("Isertly",con);
        com.CommandType = CommandType.StoredProcedure;
        com.Parameters.Add("@lyName", SqlDbType.VarChar,20).Value = TextBox1.Text;
        com.Parameters.Add("@lyAddress", SqlDbType.VarChar, 80).Value = TextBox2.Text;
        com.Parameters.Add("@lyPhone", SqlDbType.Int).Value = TextBox3.Text;
        com.Parameters.Add("@lyShandset", SqlDbType.Int).Value = TextBox4.Text;
        com.Parameters.Add("@lyFax", SqlDbType.VarChar, 50).Value = TextBox5.Text;
        com.Parameters.Add("@lyEmail", SqlDbType.VarChar, 50).Value = TextBox6.Text;
        com.Parameters.Add("@lyMotrf", SqlDbType.VarChar, 100).Value = TextBox7.Text;
        com.Parameters.Add("@lyGut", SqlDbType.Text).Value = TextBox8.Text;
        con.Open();
        com.ExecuteNonQuery();
        con.Close();执行到com.ExecuteNonQuery();说String不能转换成Int32这是怎么回事!请大侠帮帮我!谢谢!

解决方案 »

  1.   

    com.Parameters.Add("@lyPhone", SqlDbType.Int).Value = TextBox3.Text; 
    com.Parameters.Add("@lyShandset", SqlDbType.Int).Value = TextBox4.Text; 改成com.Parameters.Add("@lyPhone", SqlDbType.Int).Value = Convert.ToInt32(TextBox3.Text); 
    com.Parameters.Add("@lyShandset", SqlDbType.Int).Value = Convert.ToInt32(TextBox4.Text); 
      

  2.   

         com.Parameters.Add("@lyPhone", SqlDbType.Int).Value = Convert.ToInt32(TextBox3.Text); 
         com.Parameters.Add("@lyShandset", SqlDbType.Int).Value = Convert.ToInt32(TextBox4.Text); 
      

  3.   

    com.Parameters.Add("@lyPhone", SqlDbType.Int).Value = TextBox3.Text; 
    com.Parameters.Add("@lyShandset", SqlDbType.Int).Value = TextBox4.Text; 
    很清楚的说了,string不能转换为int32。。textbox.text是string,前面又是int,就不行咯。。
    Int32.Parse转换成int型就可以了
      

  4.   

    一个文本框的数值是字符串类型(string)的 
    而你的数据库里面该字段又是数字类型(int)的
    当然就会报错啦 你自己仔细看看数据类型是否符合了