用SQL语句Count(*),得到两个表相关的一个数据变量!再用这个变量的值乘以20,显示这个相乘后的结果在页面上!但老提示“无法将类型“int”隐式转换为“string””我已经把从数据库读出来的变量用Convert.ToInt32转换,但依然不行,下面是代码,麻烦高手指教一下!谢谢!祝新年快乐!鼠年,什么都鼠一鼠二!string DataType = ConfigurationManager.ConnectionStrings["CarConnection"].ConnectionString;
string selectSQL = "Select count(*) From QA,Temp Where QA.ID=Temp.QA_ID AND
QA.RightAnswer=Temp.ChioceAnswer AND Temp.UserName='" + Session["UserName"] + "' "; SqlConnection Conn = new SqlConnection(DataType);
SqlCommand SelectCmd = new SqlCommand(selectSQL, Conn); Conn.Open();
SqlDataReader SDR = SelectCmd.ExecuteReader();
SDR.Read(); Count.Text = SDR[0].ToString(); Point.Text = Convert.ToInt32(SDR[0].ToString()) * 20;
string selectSQL = "Select count(*) From QA,Temp Where QA.ID=Temp.QA_ID AND
QA.RightAnswer=Temp.ChioceAnswer AND Temp.UserName='" + Session["UserName"] + "' "; SqlConnection Conn = new SqlConnection(DataType);
SqlCommand SelectCmd = new SqlCommand(selectSQL, Conn); Conn.Open();
SqlDataReader SDR = SelectCmd.ExecuteReader();
SDR.Read(); Count.Text = SDR[0].ToString(); Point.Text = Convert.ToInt32(SDR[0].ToString()) * 20;
string selectSQL = "Select count(*) From QA,Temp Where QA.ID=Temp.QA_ID AND
QA.RightAnswer=Temp.ChioceAnswer AND Temp.UserName='" + Session["UserName"] + "' "; SqlConnection Conn = new SqlConnection(DataType);
SqlCommand SelectCmd = new SqlCommand(selectSQL, Conn); Conn.Open();
SqlDataReader SDR = SelectCmd.ExecuteReader();
SDR.Read(); Count.Text = SDR[0].ToString(); Point.Text = Convert.ToInt32(SDR[0].ToString()) * 20;
我的Count.Text是用来显示从数据库得到的变量!而另外的 Point.Text是按照变量的值来再乘以20得出总数!两个应该是没有明显的关系的!也要转换吗??Point.Text = Convert.ToInt32(SDR[0].ToString()) * 20; 这句我有转换呀!请指教!非常谢谢!
Point.Text = Convert.ToInt32(SDR[0].ToString()) * 20;
//point.text应该是string型吧,而右边返回的却是int型,所以出错
//正确代码应该象这样
Point.Text = (Convert.ToInt32(SDR[0].ToString()) * 20).ToSring();