我想问一下将int转换为字符串plz的情况全部阅读 [英] i want to ask about conversion of int to string plz read all

查看:84
本文介绍了我想问一下将int转换为字符串plz的情况全部阅读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

im使用ms access数据库,其中我有2个表1是配方,第二个1是注释.在配方中,我的id字段是自动编号类型,在注释中它是文本,并且在插入注释时获取了id配方表中配方的说明,以便如何在字符串中转换该ID,以便我可以在注释表中插入该ID ....例如:->

i m using ms access database and in that i have 2 tables 1 is recipe and second 1 is comments.in recipe my id field is of autonumber type and in comments it is text and at the time of insertion in comments i m retreiving id of recipe from recipe table so how to convert that id in string so that i can insert that id in the comment table ....for exmple->

DateTime currdate = DateTime.Now.Date;
            connection();
            OleDbCommand cmd1 = new OleDbCommand("select ID from addrecipes where [IsActive]=yes", con);
            OleDbDataReader dr;
            dr = cmd1.ExecuteReader();
            
            if (dr.Read())
            {
                
               session["recid"] = dr["ID"].ToString();

            }
            OleDbCommand cmd = new OleDbCommand("insert into addcomment (Uname,dname,comment,datecomment,uid,ID,IsActive) values('" + Session["uid"].ToString() + "','" + Session["txtfullname"].ToString() + "','" + txtdesc.Text + "','" + currdate + "','" + Session["idd"].ToString() + "','"+session["recid"].ToString()+"','Yes')", con);
            cmd.ExecuteNonQuery();
            con.Close();
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Success", "<script>alert('Post Added Successfully');window.location.href ='recipes.aspx'; </script>", false);

推荐答案

您可以使用ToString()Convert.ToString()将整数转换为字符串.

在查询中使用"可以确保将其另存为字符串.
确保您的db字段也是一个字符串.
You can use either ToString() or Convert.ToString() to convert to an integer to a string.

Using '''' in the query will make sure it is saved as a string.
Make sure your db field is a string as well.


删除位于 session ["recid"].ToString()周围的引号('')您的SQL命令,它将被Access DB提供程序视为整数.

我的意思是:
Session ["idd"].ToString()+''," + session ["recid"].ToString()+,''Yes'')",con);
remove embracing quote signs('') around the session["recid"].ToString() in your SQL command and it will treated as an integer by Access DB provider.

I mean this :
Session["idd"].ToString() + "'',"+session["recid"].ToString()+",''Yes'')", con);


这篇关于我想问一下将int转换为字符串plz的情况全部阅读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆