数据库中有一张表,里面有,员工编号(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();
都是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();
解决方案 »
- 求qq空间上的效果
- 请问如何在sqldatareader 通过字段名引用值的情况下,使用 变量 来表示字段的名称,高手请帮忙解答!
- 这句脚本为什么会报错
- GridView如何添加一列超链接?
- 求助啊 头都搞晕了
- ASP.NET中用什么方法设置 “验证码”?
- asp.net 发送邮件
- 怎么样把一个datatable数据写成一个xml文件了?
- Configuration Error 急急
- 简单!怎么使用DataGrid的高度根据记录调节?
- DATAGRID通过BUTTON添加数据遇到问题了!
- petshop3.0中的方法只有sqldatareader 的,如何能改写一个dataset 的,且要能使用它的重载方法,且要用PrepareCommand
int yg;
try
{
yg = int.Parse(TextBox1.Text);
}
catch
{
//提示
}
你可以强制转换阿,用Convert.tosingle(TextBox2.Text)....
可以用<asp:RegularExpressionValidator ValidationExpression="^\d*$" ></asp:RegularExpressionValidator>验证是否是数字输入