无法将类型“int”隐式转换为“byte”。
        byte a = 1;
        byte b = 2;
        byte c = 3;
        a = b + c;

为什么最下面b,c变成int型了呢= =

2个回答

byte 表示一个字节,他的表示范围[-128 127],
byte a = 1;
byte b = 2;
byte c = 3;

都在这个范围之内,没有问题。
这里还有一个问题 就是我们写的整数,没有明确指出类型(比如说 byte b = 2;中的2) 系统默认是int的,
那么为什么不会编译出错呢,这里( 我认为 )这个整数如果没有超出范围(比如 byte b = 2;在范围之内),编译系统有个自动转换。
那么a = b + c; ;怎么又会编译出错呢,而且 a,b都是byte型的,这里java又有自己的一个机制,就是防止两个小数相加超出自己所表示的范围,把a ,b变成 int 在相加。相加后也是int 型(注意这里的int 和 上面说的没有指出类型的整数默认是int 有区别,这里相当于你自己实际定义的了 例 int c=0; 系统不会在将这种明确规定数据类型的数做出自动转换的。转换也要自己强制类型转换c=byte(a+b); 这样看来好像更符合防止两个数相加超出自己表示范围的机制)。
c=a+2;和c= a + b;情况差不多。
byte c=1+2;这个就好理解了,编译器是把 1+2 看作一个整体的 就是3了,3

不是 b c 变成int了 是b+c 是int的。byte的比int低。相加是会自动转换成int.

aahuachun
aahuachun 哦,这样,谢谢了。
接近 6 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
无法将类型"byte"隐式转换为"byte[]"
byte firstByte = Convert.ToByte(serialPort.ReadByte());rn int bytesRead = serialPort.BytesToRead;rn byte[] bytesData = new byte[bytesRead + 1];rn bytesData[0] = firstByte;rn for (int i = 1; i <= bytesRead; i++)rn bytesData = (byte)(serialPort.ReadByte());rn txtReceive.Text = System.Text.Encoding.Default.GetString(bytesData);rnrnrnbytesData = (byte)(serialPort.ReadByte());rn這個出現了 无法将类型"byte"隐式转换为"byte[]" 的問題 請問怎麼解決?
无法将类型"byte[]"隐式转换为"byte"!!!
rn//16进制格式的string 转成byte[]rn public static byte[] GetBytes(string hexString, out int discarded)rn rn discarded = 0;rn string newString = "";rn char c;rn // remove all none A-F, 0-9, charactersrn for (int i = 0; i < hexString.Length; i++)rn rn c = hexString[i];rn if (Uri.IsHexDigit(c))rn newString += c;rn elsern discarded++;rn rn // if odd number of characters, discard last characterrn if (newString.Length % 2 != 0)rn rn discarded++;rn newString = newString.Substring(0, newString.Length - 1);rn rnrn int byteLength = newString.Length / 2;rn byte[] bytes = new byte[byteLength];rnrnrn string hex;rn int j = 0;rn for (int i = 0; i < bytes.Length; i++)rn rn hex = new String(new Char[] newString[j], newString[j + 1] );rnrnrn [color=#FF0000] bytes[i] = HexToByte(hex); //此处提示 无法将类型"byte[]"隐式转换为"byte"!!![/color]rn j = j + 2;rn rn return bytes;rn rnrnrn private static byte[] HexToByte(string hexString)rn rn byte[] returnBytes = new byte[hexString.Length / 2];rn for (int i = 0; i < returnBytes.Length; i++)rn returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);rn return returnBytes;rn rnrnrnrn在线等。
无法将类型“System.IntPtr”隐式转换为“byte[]”
public bool MessageBackMethod(int lCommand, ref HKNetSDK.CHCNetSDK.NET_DVR_ALARMER pAlarmer, IntPtr pAlarmInfo, uint dwBufLen, IntPtr pUser)rn rn if (lCommand == 0x1112)rn rn MessageBox.Show(pAlarmInfo.ToString());rn HKNetSDK.CHCNetSDK.NET_VCA_FACESNAP_RESULT struFaceSnap = new CHCNetSDK.NET_VCA_FACESNAP_RESULT();rn struFaceSnap = (CHCNetSDK.NET_VCA_FACESNAP_RESULT)Marshal.PtrToStructure(pAlarmInfo, typeof(CHCNetSDK.NET_VCA_FACESNAP_RESULT));rn if (struFaceSnap.pBuffer1 != null)rn rn byte[] bs = struFaceSnap.pBuffer1;rn ShowAndSavePictureAiCamera(bs);rn searchComparePic(bs);rn rn rnrnrnC#小白,第一次接触IntPtr类型指针报错不知道如何处理指点一下
无法将类型“string”隐式转换为“int?”
[code=C#]rnstring ID = System.Convert.ToString(Request["ID"]);rn DataSet ds = blluser.GetList("UserId='" + ID + "'");rn modeluser.UserId = ID;rn modeluser.UserGrade = this.cboUserGrade.SelectedValue;rn modeluser.UserPoints = this.lblIntegral.Text.Trim(); //UserPoints是个int类型,提示错误:无法将类型“string”隐式转换为“int?”,怎么改呀rn[/code]
无法将类型“int”隐式转换为“bool”
Int32 r1;rn......rnif (r1 & 4 == 0)rn rn todo;rn rn以上语句在执行时出错,报错内容是:rn[color=#FF0000]错误 1 运算符“&”无法应用于“int”和“bool”类型的操作数[/color]rn查不到这类内容,晕菜了rn请求指点,谢了。
无法将类型“int”隐式转换为“bool
如题:rn相关代码rn[code=C#]rnpublic class UserModelrnprivter int _userIsStop;rnpublic int userIsStoprngetreturn _userIsStop;rnset_userIsStop=value;rnrnrnModel.UserModel userInfo = new Model.UserModel ();rnuserInfo.userIsStop = int.Parse(e.CommandName);rn[/code]rnCommandName 为repeater模版列中LinkButton控件的CommandName 值为"True" 或 "False"
无法将类型“int”隐式转换为“string”
protected void ButAdd_Click(object sender, EventArgs e)//添加按钮rn rn Model.Goods goods = new Model.Goods();rn string GoodsType = DdlAddType.SelectedValue.ToString().Trim();//获取下拉列表框所选的类型名称rn goods.TypeID = Convert.ToInt32(BLL.GoodsManager.getTypeId(GoodsType).Tables[0].Rows[0][0]);//将类型名 称传入getTypeId方法,获取TypeIDrn rnGoods是个商品类,它有个int型字段TypeID,TypeID与商品类型表tbl_type中的TypeID关联,在业务层BLL.GoodsManager类中有下面这个方法:rnrnpublic static DataSet getTypeId(string GoodsType) //获取TypeID并返回一个datasetrn rn string sql = "select id from tbl_type where type_name='" + GoodsType + "'";rn DataSet ds = DAL.DBHelper.getDS(sql);rn return ds;rn rn 为什么在点添加按钮后,编译器老是报错,无法将类型“int”隐式转换为“string”,错误的就是:rn goods.TypeID = Convert.ToInt32(BLL.GoodsManager.getTypeId(GoodsType).Tables[0].Rows[0][0]);这句,rn请大家帮忙看看啊,谢谢了。rnrn
无法将类型“int”隐式转换为“System.Data.SqlClient.SqlDataReader
protected void Page_Load(object sender, EventArgs e)rn rn if ((string)Session["userRole"] != "0")rn Response.Redirect("Login.aspx");rn string tn = (string)Session["userName"];rn SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString);rn SqlCommand cmd = conn.CreateCommand();rn cmd.CommandText = "select * from 课程 where 教师号='" + tn + "'";rn conn.Open();rn SqlDataReader dr = cmd.ExecuteNonQuery();//问题所在处1rn GridView1.DataSource = dr;rn GridView1.DataBind();rn dr.Close();rn SqlCommand cmd1 = conn.CreateCommand();rn cmd1.CommandText = "select 姓名 from 教师 where 教师号='" + tn + "'";rn SqlDataReader dr1 = cmd1.ExecuteNonQuery();//问题所在处2rn dr1.Read();rn LabMes.Text = (string)dr1[0] + "老师的任课情况:";rn Session["teacher"] = (string)dr1[0];rn conn.Close();rn
无法将类型“int”隐式转换为“System.Data.SqlClient.SqlDataReader”
string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["TextconnectionString"].ToString();rn SqlConnection myStr = new SqlConnection(connStr);rnrn //添加数据rn SqlCommand Insert = new SqlCommand("insert into table1(Name,Sex)values('张三','男')",myStr);rn Insert.ExecuteNonQuery();rnrn //查询数据rn SqlCommand cmd = new SqlCommand("select * from table1",myStr);rn SqlDataReader dr1 = cmd.ExecuteNonQuery();rnrn while (dr1.Read())rn rn Response.Write(dr1["Name"]);rn Response.Write(dr1["Sex"]);rn Response.Write(" ");rn rn dr1.Close();rnrnrnrn怎么修改这个错误呢?编译器错误消息: CS0029: 无法将类型“int”隐式转换为“System.Data.SqlClient.SqlDataReader”rnrn源错误:rnrn rnrn行 25: //查询数据rn行 26: SqlCommand cmd = new SqlCommand("select * from table1",myStr);rn行 27: SqlDataReader dr1 = cmd.ExecuteNonQuery();rn行 28: rn行 29: while (dr1.Read())rn rn
无法将类型“System.Collections.Generic.List”隐式转换为“int”
运行时出这个错,求大神指点如何解决rn
无法将类型“System.Data.SqlClient.SqlDataReader”隐式转换为“int”
public static SqlDataReader GetTopData(string sql)rn rn SqlConnection conn = DBClass.GetConnection();rn conn.Open();rn SqlCommand cmd = new SqlCommand(sql, conn);rn tryrn rn cmd.ExecuteScalar();rn SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);rn return dr;rn rn catch (Exception ex)rn rn throw (ex);rn rnrn rnrn string searchSql = @"select count(*) from userinfo where uid like '%'"+tbKey.Text.Trim()+"'%' or uname like '%'"+tbKey.Text.Trim()+"'%'";rn int o = SqlHelper.GetTopData(searchSql); //查询总的有多少条数据rnrnrn哪个大哥 教我把这个count(*)值 取出来
无法将类型“string”隐式转换为“int”
代码如下,不明白C#干嘛喜欢把东西转来转去的,事项一次觉得技术先进吗?!!!!!!!rnrnrnpublic partial class TrainManage_Train_TrainRecord : System.Web.UI.Pagernrn private int xT_ID = "sid";//培训ID 报错这一句无法将类型“string”隐式转换为“int”rn private string DutySql = "select a.P_ID,a.P_NAME, case a.P_SEX when 0 then '男' when 1 then '女' when 2 then '未知'end as P_SEX ,a.P_DEPARTMENT,c.RP_RESULT,c.RP_PEROSN_ID,c.RP_TRAIN_ID,b.T_ID,b.T_NAME,b.T_START_TIME,b.T_OVER_TIME,d.INFO_ID,d.INFO_NAME from RS_Person a,RS_TRAIN b,RS_TRAIN_PERSON c, RS_D_INFOMATION d where a.P_ID = c.RP_PEROSN_ID and b.T_ID = c.RP_TRAIN_ID and d.INFO_ID=a.P_DEPARTMENT and b.T_ID='xT_ID' ";//这句SQL语句查处3表里的数据。rnrn private class _Noticern rn public static string RecordCount;rn rn protected void Page_Load(object sender, EventArgs e)rn rn if (!IsPostBack)rn rnrnrn rn //int xID = Convert.ToInt32(Request.QueryString["id"]);rnrn //int id = Int32.Parse(this.Request.QueryString["id"]);//编号rn int sid = Int32.Parse(this.Request.QueryString["id"].ToString()); rn Response.Write(sid);rn这里可以得出 sid的值 得出为8 而且我觉得这里已经 int 了。。哪里也没看到类型“string”隐式 这都什么跟什么错啊。
无法将类型“double”隐式转换为“int”
int kkje=06*Double.Parse("+kkts.Text+");rn报错,(304): 无法将类型“double”隐式转换为“int”rn求解rn
无法将类型"int"隐式转换为"string"
private void Page_Load(object sender, System.EventArgs e)rn rn if(!IsPostBack)rn rn if(Request.QueryString["ID"]!=null&& Request.QueryString["ID"].Length>0)rn [color=#FF0000]ID=int.Parse(Request.QueryString["ID"]);[/color]rn string connectionString=ConfigurationSettings.AppSettings["connectionString"];rn SqlConnection con=new SqlConnection(connectionString);rn con.Open();rnrn string Sql="select * from S_News where ID=" +ID;rn SqlCommand com=new SqlCommand(Sql,con);rn SqlDataReader reader=com.ExecuteReader();rn if(reader.Read())rn rn lTitle.Text=reader["Title"].ToString();rn lAdduser.Text=reader["Adduser"].ToString();rn lAddtime.Text=reader["Addtime"].ToString();rn rn elsern rn lresult.Text="没有找到相应的信息";rn rn reader.Close();rn con.Close();rn rn
无法将类型“int”隐式转换为“System.Data.OleDb.OleDbType”
[code=csharp] PlanWork planwork = new PlanWork();rn BLL.PlanWorkManager.AddPlanWork(planwork);rn planwork.planworkID = Int32.Parse(textBox_id.Text);rn planwork.WorkerID = textBox_num.Text.ToString();rn planwork.Worktime = dateTime_worktime.Value;rn planwork.Afworktime = dateTime_aftime.Value;rn planwork.Hours = textBox_hour.TextLength;rn planwork.Class = com_class.Text.ToString();rn planwork.Handler = textBox_hander.Text.ToString();rn planwork.Date = dateTime_date.Value;[/code]rn我用的是access数据库,planworkID是长整型自动编号, planwork.planworkID = Int32.Parse(textBox_id.Text);显示错误为:无法将类型“int”隐式转换为“System.Data.OleDb.OleDbType”。存在一个显式转换(是否缺少强制),请问该怎么修改呢?
无法将类型“string”隐式转换为“int”????????????????????????
rnrn private void data_disp(object source, System.Web.UI.WebControls.DataListCommandEventArgs e)rn rn switch(e.CommandName)rn rn case "alldata":rn DataList1.SelectedIndex=e.Item.ItemIndex;rn break;rnrn case "simpledata":rn DataList1.SelectedIndex=-1;rn break;rnrn case "editdata":rn DataList1.EditItemIndex=e.Item.ItemIndex;rn break;rn case "canceldata":rn DataList1.EditItemIndex=-1;rn break;rn case "savedata":rn rec_disp();rn rn rn TextBox text_price=DataList1.Items[e.Item.ItemIndex].FindControl["txt_unitprice"];//c:\inetpub\wwwroot\Web9\WebForm5.aspx.cs(103): 在不带括号的情况下引用了方法“System.Web.UI.Control.FindControl(string)”rnrn rn ds.Tables["Products"].Rows[e.Item.ItemIndex].ItemArray["unitprice"]=text_price.Text;//c:\inetpub\wwwroot\Web9\WebForm5.aspx.cs(106): 无法将类型“string”隐式转换为“int”rnrn TextBox text_stock=DataList1.Items[e.Item.ItemIndex].FindControl["txt_stock"];//c:\inetpub\wwwroot\Web9\WebForm5.aspx.cs(108): 在不带括号的情况下引用了方法“System.Web.UI.Control.FindControl(string)”rnrn ds.Tables["Products"].Rows[e.Item.ItemIndex].ItemArray["unitinstocks"]=text_stock.Text;//c:\inetpub\wwwroot\Web9\WebForm5.aspx.cs(110): 无法将类型“string”隐式转换为“int”rnrn SqlDataAdapter da=new SqlDataAdapter();rn SqlCommandBuilder cb=new SqlCommandBuilder(da);//??rn if (da.Update(ds,"products")>0)rn rn DataList1.EditItemIndex=-1;rn rn DataList1.DataSource=ds.Tables["products"];rn DataList1.DataBind();rn break;rnrnrn rn rn rec_disp();rn DataList1.DataSource=ds.Tables["products"];rn DataList1.DataBind();rnrnrn
c# 无法将类型“byte”隐式转换为“byte[]”
c# 部分代码rn string[] str = content.Split('|');rn byte[] btyes = new byte[str.Length];rnrn for (int i = 0; i < str.Length; i++)rn rn if (str != null)rn rn if (str.Length > 0)rn rn btyes = Convert.ToByte(str) ;rn rn rn rnrnrn这里提示 btyes = Convert.ToByte(str) 无法将类型“byte”隐式转换为“byte[]” rn应该怎么转换呢?高手求解rn
无法将类型“”隐式转换为“。。。
[img=https://img-bbs.csdn.net/upload/201705/15/1494834389_512033.png][/img]该怎么解决这问题?
无法将string隐式转换为int,如图
[img=https://img-bbs.csdn.net/upload/201605/02/1462182953_170772.png][/img][img=https://img-bbs.csdn.net/upload/201605/02/1462183156_839503.png][/img]
CS0029: 无法将类型“byte[]”隐式转换为“System.Drawing.Image”
products pro = new products();//引用products类rnrn//上传图片rnif (uploadFile.PostedFile.FileName != "")rn rn //----------- update图片rn rn .......rn .....rn //下面是传图片rn Stream imagedatastream;rn imagedatastream = Request.Files["uploadFile"].InputStream;rn int imagedatalen = Request.Files["uploadFile"].ContentLength;rn string imagedatatype = Request.Files["uploadFile"].ContentType;rnrn byte[] image = new byte[imagedatalen];rn imagedatastream.Read(image, 0, imagedatalen);rnrnrn pro.proimage = image;rn pro.product_add();rn rnrnrnproduct_add方法:rnrnrnrnpublic Image proimage;//申明proimagernrnpublic bool product_add()rn rn SqlParameter[] Params = new SqlParameter[18];rn 。。。rn 。。。rn Params[17] = db.MakeInParam("@ProductPicture", SqlDbType.Image, 1000, proimage);rn int count = -1;rn count = db.RunProc("product_add", Params);//执行product_add存储过程rn if (count > 0)rn return true;rn else return false;rn rnrnrn[size=12px]编译错误[/size] rn说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 rnrn编译器错误信息: CS0029: 无法将类型“byte[]”隐式转换为“System.Web.UI.WebControls.Image”rn源错误:rnrn rnrn行 283: //Bitmap bm = (Bitmap)Image.FromStream(ms);rn行 284:rn[color=#FF0000]行 285: pro.proimage = image;[/color]行 286:rn行 287:rn rnrn源文件: e:\www\njut_c2c\product_add.aspx.cs 行: 285 rnrnrnrn显示详细的编译器输出:rnrnrnC:\Program Files\Microsoft Visual Studio 8\Common7\IDE> "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe" /t:library /utf8output /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Services\2.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.EnterpriseServices\2.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\WINDOWS\assembly\GAC_32\System.Web\2.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Web.Mobile\2.0.0.0__b03f5f7f11d50a3a\System.Web.Mobile.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\assembly\dl3\520c0345\001b4bea_73e0c701\FredCK.FCKeditorV2.DLL" /R:"C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Code.6dkny_u-.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\assembly\dl3\421b2272\00ec3307_53fac501\Microsoft.Web.UI.WebControls.DLL" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Design\2.0.0.0__b03f5f7f11d50a3a\System.Design.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_6btnn1v4.dll" /out:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.dll" /D:DEBUG /debug+ /optimize- /win32res:"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\sjbfnvn7.res" /w:4 /nowarn:1659;1699 "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.4.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.17.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.1.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.10.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.19.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.2.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.8.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.12.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.14.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.5.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.7.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.6.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.11.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.0.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.3.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.9.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.13.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.18.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.16.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.20.cs" "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\njut_c2c\00c74ea8\76daac43\App_Web_sjbfnvn7.15.cs"rnrnrnMicrosoft (R) Visual C# 2005 编译器 版本 8.00.50727.42rn用于 Microsoft (R) Windows (R) 2005 Framework 版本 2.0.50727rn版权所有 (C) Microsoft Corporation 2001-2005。保留所有权利。rnrne:\www\njut_c2c\Order_Detail.aspx.cs(13,7): warning CS0105: “System.Data.SqlClient”的 using 指令以前在此命名空间中出现过rne:\www\njut_c2c\product_add.aspx.cs(285,32): error CS0029: 无法将类型“byte[]”隐式转换为“System.Web.UI.WebControls.Image”rnrn rnrnrnrn
无法将类型“int”隐式转换为“System.Data.SqlClient.SqlDataReader”是怎么回事啊?
[code=C#]String strcon = "Data Source=yufenghua\\yufenghua;User ID=sa;Password=317448437;DataBase=hospital";//连接字符串rn SqlConnection con = new SqlConnection(strcon);rn SqlCommand cmder = con.CreateCommand();rn cmder.CommandText = "insert into project(itemdate,itemtitle,itemcontent,itemscore) values('" + Convert.ToDateTime(ida.Text) + "','" + iti.Text + "','" + ide.Text + "','" + Convert.ToInt32(isc1.Text) + "')";rn con.Open();rn SqlDataReader dr = cmder.ExecuteNonQuery(); ;rn con.Close();rn Response.Write("添加项目成功!!! 继续添加项目     去评分");[/code]rn结果在运行时出现了这个错误,我怎么也想不明白,大家帮忙看看怎么回事?
c#无法将类型int隐式转换为string怎么解决?
c#无法将类型int隐式转换为string怎么解决?rn entity.userid = txtUserid.Text;rn rn if (entity.userid.Length <= 0)rn rn txtUserid.Focus();rn throw new Exception("UserID不能为空");rn
无法将类型“string”隐式转换为“int”。拜求!!!!谢谢!!!
我用C#做个很简单的倒计时,在textBox1中输入数据m,然后利用timer1控件,就m--倒计时啊。运行报错:无法将类型“string”隐式转换为“int”。所有代码都在下面了。大哥大姐教教我吧。谢谢。rn rnint m;rnrnprivate void textBox1_TextChanged(object sender, EventArgs e)rn rn if(this.textBox1.Text != "")rn rn m = this.textBox1.Text;rn rn rnrnprivate void timer1_Tick(object sender, EventArgs e)rn rn rn m--;rn this.label2.Text = m.ToString()+"秒";rn label2.Refresh();rn rnrn private void button1_Click(object sender, EventArgs e)rn rn this .timer1.Enabled =true;rn
C#新手求解 无法将类型“string”隐式转换为“int”
[code=C#]rnrnprotected void Button1_Click(object sender, EventArgs e)rn rn WebModel.UserInfo model = new WebModel.UserInfo();rn model.UserId = TextBoxUserId.Text;rn model.UserName = TextBoxUserName.Text;rn model.Password = TextBoxPassword.Text;rnrn if (dal.Add(model) == 0)rn rn MessageBox.ResponseScript(this.Page, "alert('添加成功');");rn Response.Redirect("UserInfo.aspx");rn rn elsern rn MessageBox.ResponseScript(this.Page, "alert('添加失败');");rn rn rnrn[/code]rnrn[color=#FF0000]model.UserId = [u]TextBoxUserId[/u].Text;[/color]rnrn数据库这3个字段都是varchar类型,UserID原来是int类型,现在我改成了varchar类型。三层模式写的
CS0029: 无法将类型“int”隐式转换为“System.Data.OleDb.OleDbDataReader”错误
public void page_Load(Object sender,EventArgs e)rnrnrn string path=Request.PhysicalPath;//取得路径rn int len=path.Length;//路径的长度rn int ff=path.LastIndexOf("\\");//取路径path中最后一个"\"的位置rn string strmdb=path.Substring(0,(ff+1));rn strmdb=strmdb+"thedata\\thedata.mdb";//access数据库的路径rn string mdbconnection="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+strmdb;rn OleDbConnection conn=new OleDbConnection(mdbconnection);rn conn.Open();//打开数据库rn OleDbCommand mdbcomm=new OleDbCommand("insert into userlist(username,remark,comment) values('朱从海','dfds','是我弟弟')",conn);rn OleDbDataReader rs=mdbcomm.ExecuteNonQuery();rnrnrn表结构:id(标识) username(文本型) remark(文本型) comment(文本型)rnrn提示错误:编译器错误信息: CS0029: 无法将类型“int”隐式转换为“System.Data.OleDb.OleDbDataReader”rn行 20: OleDbDataReader rs=mdbcomm.ExecuteNonQuery();rnrn这是怎么回事呀,rnrn若把("insert into userlist(username,remark,comment) values('朱从海','dfds','是我弟弟')"改成“select * from userlist”把ExecuteNonQuery()改成ExecuteReader()则正常~~
switch语句出错!无法将类型“int”隐式转换为“bool”
[code=C#]rnEvaluationVariable Test = new EvaluationVariable();rn switch (Test.nowNL < 5)rn rn case Test.nowNL = 1:rn Test.ddzjf = Test.nowM;rn Test.nowNL = Test.nowNL + 1;rn Session["EvalTest"] = Test;rn QuBd(day, Test.nowNL);rn break;rn case Test.nowNL = 2:rn Test.jxdzjf = Test.nowM;rn Test.nowNL = Test.nowNL + 1;rn Session["EvalTest"] = Test;rn QuBd(day, Test.nowNL);rn break;rn case Test.nowNL = 3:rn Test.synljf = Test.nowM;rn Test.nowNL = Test.nowNL + 1;rn Session["EvalTest"] = Test;rn QuBd(day, Test.nowNL);rn break;rn case Test.nowNL = 4:rn Test.yyjf = Test.nowM;rn Test.nowNL = Test.nowNL + 1;rn Session["EvalTest"] = Test;rn QuBd(day, Test.nowNL);rn break;rn rnrnrn[/code]rnrnEvaluationVariable里面所涉及到的函数:rn[code=C#]rn public int nowNLrn rn get return _nowNL; rn set _nowNL = value; rn private int _nowNL = 0;rn[/code]rn大家看看我这个switch 有什么错误?在运行时出错:rn编译器错误消息: CS0029: 无法将类型“int”隐式转换为“bool”rnrn源错误:rnrn rnrn行 99: switch (Test.nowNL < 5)rn行 100: rn[color=#FF0000]行 101: case Test.nowNL = 1:[/color]行 102: Test.ddzjf = Test.nowM;rn行 103: Test.nowNL = Test.nowNL + 1;rn rn
端口打不开 或 无法将类型“uint”隐式转换为“int”
const int GENERIC_READ = 0x80000000; 无法将类型“uint”隐式转换为“int”rnrnconst int GENERIC_WRITE = 0x40000000; 无法将类型“uint”隐式转换为“int”rnrn rnconst int OPEN_EXISTING = 3;rnrn[DllImport("kernel32.dll")rnpublic static extern IntPtr CreateFileA(string lpFileName, int dwDesiredAccess, int dwShareMode, int lpSecurityAttributes, int dwCreationDisposition, int dwFlagsAndAttributes, int hTemplateFile);rnprivate void Button1_Click(Object sender, EventArgs e)rnrn IntPtr iHandle = CreateFileA("LPT1", GENERIC_READ|GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);rn if(iHandle.ToInt32() == -1)rn rn MessageBox.Show("can not open port");rn rn elsern rn MessageBox.Show("Open Success!");rn FileStream fs = new FileStream(iHandle, FileAccess.ReadWrite);rn StreamReader sr = new StreamReader(fs);rn StreamWriter sw = new StreamWriter(fs);rn rnrn按上述方法,则出现无法将类型“uint”隐式转换为"int“,若是把int改为long ,则rn端口打不开.
错误 CS0029: 无法将类型“int”隐式转换为“System.Data.OleDb.OleDbDataReader
string name = Request.Form["ccc"];rn string id=Request.Form["id"];rn string path = ConfigurationManager.AppSettings["path"];rn string provider = ConfigurationManager.ConnectionStrings["provider"].ConnectionString;rn OleDbConnection Connection = new OleDbConnection(provider + Server.MapPath(path));rn Connection.Open();rn string sql = "update essay set content = "+name+" where id ="+id;rn OleDbCommand cmd = new OleDbCommand(sql, Connection);rn OleDbDataReader objDataReader=cmd.ExecuteNonQuery();rnrnrn以上是代码,好像没什么问题,网上教程都这么写的,有人说最后句可以直接cmd.ExecuteNonQuery();式了也不行,会变成说是UPDATE语法错误。请指教。rn
CS0029: 无法将类型“object”隐式转换为“int” 如何解决?
我的一个aspx中有如下一个QueryMaxXh函数,但在page_load 中调用出错,rn请教各位高手?rnprotected int QueryMaxXh()rn rn int intXH=0; rn rn objConnection= new SqlConnection(strConnection);rn objConnection.Open();rn rn strSQL="select max(xh) as maxxh from kanameTmp";rn dataSet = new DataSet(); rn objAdapter = new SqlDataAdapter(strSQL, objConnection);rn objAdapter.Fill(dataSet, "kanameTmp");rn DataTable objTable = dataSet.Tables[0];rn DataRow objRow = objTable.Rows[0];rn rn intXH = objRow["maxxh"];rn rn return intXH;rn rn rnrnrn编译器错误信息: CS0029: 无法将类型“object”隐式转换为“int”rnrn源错误:rnrnrn行 104: DataRow objRow = objTable.Rows[0];rn行 105: rn行 106: intXH = objRow["maxxh"];rn行 107: rn行 108: return intXH;rn
CS0029: 无法将类型“int”隐式转换为“string”
编译器错误信息: CS0029: 无法将类型“int”隐式转换为“string”。。。菜鸟第一次用.net做东西,,请高手指点rnrn源错误:rnrn rnrn行 24: List lines = lineBLL.GetlineByID(lineID);rn行 25: line line = lines[0];rn行 26: lblineID.Text = line.LineID;rn行 27: txtlinename.Text = line.LineName;rn行 28: DropDownList2.Text = line.LineStart;rn rn----rnusing System;rnusing System.Data;rnusing System.Configuration;rnusing System.Collections;rnusing System.Web;rnusing System.Web.Security;rnusing System.Web.UI;rnusing System.Web.UI.WebControls;rnusing System.Web.UI.WebControls.WebParts;rnusing System.Web.UI.HtmlControls;rnusing System.Data.SqlClient;rnusing System.Collections.Generic;rnpublic partial class wangpeng_manageline_modifyline : System.Web.UI.Pagernrn protected void Page_Load(object sender, EventArgs e)rn rn if (!IsPostBack)rn rn if (Request.QueryString["lineID"] == null)rn rn Response.Redirect("linemanage.aspx");rn rn string lineID = Request.QueryString["lineID"].ToString();rn List lines = lineBLL.GetlineByID(lineID);rn line line = lines[0];rn lblineID.Text = line.LineID;//-----》提示错误在这。。。rn txtlinename.Text = line.LineName;rn DropDownList2.Text = line.LineStart;rn DropDownList1.Text = line.LineEnd;rn txtpoint.Text = line.Linepoint;rn txtlinelength.Text = line.Linelength;rn txtlineprice.Text = line.Lineprice;rn rn rn protected void Button1_Click(object sender, EventArgs e)rn rn line line = new line();rn line.LineID = lblineID.Text;rn line.LineName = txtlinename.Text;rn line.LineStart = DropDownList2.Text;rn line.LineEnd = DropDownList1.Text;rn line.Linepoint = txtpoint.Text;rn line.Linelength = txtlinelength.Text;rn line.Lineprice = txtlineprice.Text;rn lineBLL lineBLL = new lineBLL();rn int count = lineBLL.Updateline(line);rn if (count > 0)rn rn Response.Write(" ");rn rn elsern rn Response.Write(" ");rn rn rnrn
编译器错误信息: CS0029: 无法将类型“int”隐式转换为“string”
行 23: rn行 24: line.LineName = txtlinename.Text.Trim();rn行 25: line.LineStart = Convert.ToInt32(DropDownList2.SelectedItem.Value);rn行 26: line.LineEnd = Convert.ToInt32(DropDownList1.SelectedItem.Value);rn行 27: line.Linepoint = txtlinepoint.Text.Trim();rnrnwhat's the matter???
无法将类型"int"隐式转换为"string",该怎么解决?
同上rnrn我是这样定义的rnprivate int aa;rnaa = 12;rnrnTextBox1.Text=aa;rnrn然后就出现上面这个错误,这是为什么?
无法将类型“uint”隐式转换为“int”,如何解决
下面一句出现错误:无法将类型“uint”隐式转换为“int”,如何解决rnpublic const int SHCNE_INTERRUPT = 0x80000000;
CS0029: 无法将类型“string”隐式转换为“int” ......
编译器错误信息: CS0029: 无法将类型“string”隐式转换为“int”-----菜鸟问题。。请高手解答rnrn源错误:rnrn rnrn行 36: rn行 37: line line = new line();rn行 38: line.LineID = lblineID.Text;rn行 39: line.LineName = txtlinename.Text;rn行 40: line.LineStart = DropDownList2.Text;rn ---rnusing System;rnusing System.Data;rnusing System.Configuration;rnusing System.Collections;rnusing System.Web;rnusing System.Web.Security;rnusing System.Web.UI;rnusing System.Web.UI.WebControls;rnusing System.Web.UI.WebControls.WebParts;rnusing System.Web.UI.HtmlControls;rnusing System.Data.SqlClient;rnusing System.Collections.Generic;rnpublic partial class wangpeng_manageline_modifyline : System.Web.UI.Pagernrn protected void Page_Load(object sender, EventArgs e)rn rn if (!IsPostBack)rn rn if (Request.QueryString["lineID"] == null)rn rn Response.Redirect("linemanage.aspx");rn rn string lineID = Request.QueryString["lineID"].ToString();rn List lines = lineBLL.GetlineByID(lineID);rn line line = lines[0];rn lblineID.Text = line.LineID.ToString();rn txtlinename.Text = line.LineName;rn DropDownList2.Text = line.LineStart;rn DropDownList1.Text = line.LineEnd;rn txtpoint.Text = line.Linepoint;rn txtlinelength.Text = line.Linelength.ToString();rn txtlineprice.Text = line.Lineprice;rn rn rn protected void Button1_Click(object sender, EventArgs e)rn rn line line = new line();rn line.LineID = lblineID.Text;//---------->报错。。。rn line.LineName = txtlinename.Text;rn line.LineStart = DropDownList2.Text;rn line.LineEnd = DropDownList1.Text;rn line.Linepoint = txtpoint.Text;rn line.Linelength = txtlinelength.Text;rn line.Lineprice = txtlineprice.Text;rn lineBLL lineBLL = new lineBLL();rn int count = lineBLL.Updateline(line);rn if (count > 0)rn rn Response.Write(" ");rn rn elsern rn Response.Write(" ");rn rn rnrnrn
无法将类型int隐式转换为string,郁闷死了
程序中有这样一句rnrnmodel.qty=Convert.ToInt32(textBox1.Text);rnrn//model.qty=int.Parse(textBox1.Text);rnrn两种方法都不行,提示:无法将类型int隐式转换为stringrn怎么回事呢?rnmodel.qty是一个类的属性,是INT型的rn
无法将类型string隐式转换为int怎么解决
[img=https://img-bbs.csdn.net/upload/201305/22/1369198569_456228.jpg][/img]
新手求助...无法将类型"int"隐式转换为"string"
namespace ConsoleApplication2rnrn class Programrn rn static void Main(string[] args)rn rn Console.WriteLine("欢迎来到本次展览.请选择您是下面哪一类的参观者.输入类型前的代号");rn Console.WriteLine("1-1.2米以下的儿童");rn Console.WriteLine("2-大中小学生");rn Console.WriteLine("3-离休人员");rn Console.WriteLine("4-老年人");rn int number = int.Parse(Console.ReadLine());rn 1= "1.2米以下的儿童";rn 2= "大中小学生";rn 3= "离休人员";rn 4= "老年人";rn switch (number) rn case 1: Console.WriteLine("课享受免费优惠"); break; //无法将类型"int"隐式转换为"string"rn case 2: Console.WriteLine("优惠后票价20元"); break;//无法将类型"int"隐式转换为"string"rnrn case 3: Console.WriteLine("离休人员"); break;//无法将类型"int"隐式转换为"string"rnrn case 4: Console.WriteLine("老年人"); break;//无法将类型"int"隐式转换为"string"rnrn default: Console.WriteLine("不能享受优惠"); break;rn rnrn rn rn Console.ReadLine();rn rn rnrn
高手请过目,无法将类型“string”隐式转换为“int”
写了段想实现的功能是:从表File_Upload中读出最后的ID值(int),将该值*1000写入FileNameFlowNum字段,总是提示rnrn说明: 在编译向该请求提供服务所需资源的过程中出现错误。请检查下列特定错误详细信息并适当地修改源代码。 rnrn编译器错误消息: CS0029: 无法将类型“string”隐式转换为“int”rnrnrnrn[code=C#]rn SqlConnection conn = new SqlConnection(strConn);rn conn.Open();rn SqlCommand nonquery = conn.CreateCommand();rn int ID_TEMP="SELECT ID FROM File_Upload DESC";rn nonquery.CommandText = "INSERT INTO File_Upload (FileNameFlowNum) VALUES ('" + 1000 * ID_TEMP + "')";rn nonquery.ExecuteNonQuery().ToString();rn[/code]
无法将类型“int”隐式转换为“System.Data.SqlClient.SqlDataReader”?怎么解决?
如题、以下为代码:rn for (int i = 0; i <= dataGridView1.Rows.Count; i++)rn rn for (int j = 1; j <= dataGridView1.Rows.Count - 1; j++)rn rn string Department_sql = "update B3P3C_Parameters set B3P3C_Parameters_Department='" + department[i] + "' where B3P3C_Row= ‘" + j + "’";rn m_reader = m_dbclass.ExcuteOneSQL(Department_sql);rnrn rn rn rn
新手问题:无法将类型“string”隐式转换为“int”
public static int iTos(int x)rn rn return Convert.ToString(x);rn rn为什么会发生错误 无法将类型“string”隐式转换为“int”
相关热词 c#入门推荐书 c# 解码海康数据流 c# xml的遍历循环 c# 取 查看源码没有的 c#解决高并发 委托 c#日期转化为字符串 c# 显示问号 c# 字典对象池 c#5.0 安装程序 c# 分页算法