CSDN博客

img JAVAvNET

041006 A DB 乱码

发表于2004/10/6 19:20:00  795人阅读

    Q. string strSql = "INSERT INTO TBL_GYOMUTANGO ";
    strSql += "(WORD) ";
    strSql += "VALUES('" +strKey + "')";
    -->strKey 是汉字时,程序显示为乱码。

    A. 使用Parameters解决乱码
    string strSql = "INSERT INTO TBL_GYOMUTANGO ";
    strSql += "(WORD, COMMENT) ";
    strSql += "VALUES(@strKey,@strComment)";
              
    SqlCommand cmd = new SqlCommand(strSql,conn,trans);
    cmd.Parameters.Add(new SqlParameter("@strKey",SqlDbType.VarChar,50));
    cmd.Parameters.Add(new SqlParameter("@strComment",SqlDbType.NVarChar ,200));
    cmd.Parameters["@strKey"].Value = strKey;
    cmd.Parameters["@strComment"].Value = strComment;
    //SqlCommand cmd = new SqlCommand(strSql,conn);
    cmd.CommandType = CommandType.Text;
    iRet = cmd.ExecuteNonQuery();
阅读全文
0 0

相关文章推荐

img
取 消
img