返回首页

IM使用MS Access数据库中,我有2表1配方和第二个1是我的id字段是自动编号类型在评论这是文本,并在插入时间从IM retreiving配方ID意见comments.in配方配方表,因此,如何转换成字符串,ID,这样我就可以插入exmple-GT,在意见表中的id ....

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);

回答

评论会员:阿米尔Mahfoozi 时间:2012/02/06
。会议围绕在您的SQL命令["RECID"]的ToString()删除拥抱报价符号('),它将作为一个整数处理访问DB提供

我的意思是:
会议["IDD"的ToString()","会议"RECID的ToString()",'是')",CON)
评论会员:游客 时间:2012/02/06
|你可以使用任何的ToString()或Convert.ToString()转换为整数字符串。在查询中使用",将确保它作为一个字符串保存。确保你的数据库字段是一个字符串,以及