数据库中有一张表,里面有,员工编号(int),员工的底薪,奖励工资,福利工资,住房金,惩罚金,以及实际发放工资
都是float类型,怎么才能实现,实际发放工资=底薪+奖励工资+福利工资-住房金-惩罚金,也就是说实际发放工资是用程序算出来的,并且当我在textbox中输入的不是数字,是字母或其它什么东东时,怎么让它提示错误输入,我的代码如下:有个错误就是减号不能在string与string字符类型中操作,怎么改啊,各位大虾们,帮帮我吧 //float w;
//w=TextBox2.Text+TextBox3.Text+TextBox4.Text-TextBox5.Text-TextBox6.Text);
SqlConnection MyConnection = new SqlConnection("server=(local);database=bysj;Trusted_Connection=yes");
//参数查询
string insertStr =" INSERT INTO ygwage(ygid,dixin,jlwage,flwage,zfwage,chengfwage,sfwage) VALUES ";
insertStr+="(@ygid,@dixin,@jlwage,@flwage,@zfwage,@chengfwage,@sfwage)";
//生成一个 SqlCommand
SqlCommand insertCommand = new SqlCommand(insertStr, MyConnection);


insertCommand.Parameters.Add(new SqlParameter("@ygid", SqlDbType.Int));
insertCommand.Parameters["@ygid"].Value =TextBox1.Text;
            //int 型数字最多只能写10位

insertCommand.Parameters.Add(new SqlParameter("@dixin", SqlDbType.Float));
insertCommand.Parameters["@dixin"].Value =TextBox2.Text;
     
insertCommand.Parameters.Add(new SqlParameter("@jlwage", SqlDbType.Float));
insertCommand.Parameters["@jlwage"].Value =TextBox3.Text; insertCommand.Parameters.Add(new SqlParameter("@flwage", SqlDbType.Float));
insertCommand.Parameters["@flwage"].Value =TextBox4.Text; insertCommand.Parameters.Add(new SqlParameter("@zfwage", SqlDbType.Float));
insertCommand.Parameters["@zfwage"].Value =TextBox5.Text; insertCommand.Parameters.Add(new SqlParameter("@chengfwage", SqlDbType.Float));
insertCommand.Parameters["@chengfwage"].Value =TextBox6.Text;  insertCommand.Parameters.Add(new SqlParameter("@sfwage", SqlDbType.Float));
insertCommand.Parameters["@sfwage"].Value =TextBox7.Text;
//insertCommand.Parameters["@sfwage"].Value =w; MyConnection.Open();
insertCommand.ExecuteNonQuery();

解决方案 »

  1.   

    可以使用dataview来计算,不错
      

  2.   

    简单方法
    int yg;
    try
    {
    yg = int.Parse(TextBox1.Text);
    }
    catch
    {
    //提示
    }
      

  3.   

    //w=TextBox2.Text+TextBox3.Text+TextBox4.Text-TextBox5.Text-TextBox6.Text);
    你可以强制转换阿,用Convert.tosingle(TextBox2.Text)....
    可以用<asp:RegularExpressionValidator ValidationExpression="^\d*$" ></asp:RegularExpressionValidator>验证是否是数字输入
      

  4.   

    其实这个最好交给dataview来解决,我觉得效率是不一样的,而且程序看起来会更好理解,更合乎情理