C#强制转换错误
大家给我看下我的强制转换总是提示字符串输入格式错误,在线等SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=123;database=ygxx");
con.Open();
string sql = "select 缺勤 from 考勤表 where 员工编号='" + comboBox1.Text + "'";
SqlCommand c = new SqlCommand(sql, con);
c.ExecuteNonQuery();
string f = c.ExecuteScalar().ToString();
int count =System.Convert.ToInt32(f );
--------------------编程问答--------------------
ExecuteNonQuery 这个是不返回任何数据 --------------------编程问答-------------------- 1、"缺勤"列是int类型么?
2、查到几行?如果0行也会错。
改一下:
string sql = "select count(缺勤) from 考勤表 where 员工编号='" + comboBox1.Text + "'";
SqlCommand c = new SqlCommand(sql, con);
int count = (int)c.ExecuteScalar(); --------------------编程问答-------------------- SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=123;database=ygxx");
con.Open();
string sql = "select 缺勤 from 考勤表 where 员工编号='" + comboBox1.Text + "'";
SqlCommand c = new SqlCommand(sql, con);
c.ExecuteNonQuery();
string f = c.ExecuteScalar().ToString();
int count =System.Convert.ToInt32(f );
sql = "select 迟到 from 考勤表 where 员工编号='" + comboBox1.Text +"'";
SqlCommand 迟到_com = new SqlCommand(sql, con);
int countd = 迟到_com.ExecuteNonQuery();
string d;
d= 迟到_com.ExecuteScalar().ToString ();
countd= Convert.ToInt32(0);
int a = count * 5 + countd * 10;
textBox6.Text = a.ToString();
我是个新手 想实现从考勤到工资的结算 还请帮忙看看 如何实现 谢谢 --------------------编程问答--------------------
SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=123;database=ygxx");--------------------编程问答--------------------
con.Open();
string sql = "select 缺勤 from 考勤表 where 员工编号='" + comboBox1.Text + "'";
SqlCommand c = new SqlCommand(sql, con);
string f = c.ExecuteScalar().ToString();
int count = int.Parse(f);
补充:.NET技术 , C#