I'm new to using this part of the framework, so I'm hoping I've done
something obviously stupid, which someone will be able to point out in
an obvious manner.
Most of the samples I've seen involved encrypting and decrypting to and
from a file, but that's not what I want. I want to be able to insert a
string into an encryption function which outputs that encrypted string,
which could then be sent into a decryption function and spit out the
original string.
As you might expect, ultimately, I want to be able to put this string
into a database table.
Anyways, I set up a simple test page where I enter a string in a
textbox, and then run it through an encrypt, then decrypt, function, and
print out to some labels to make sure it is doing it correctly.
The encrypt part seems to work (at least the function doesn't fail), but
the decrypt function fails, with an error saying that the length of the
encrypted string is invalid. Here are the functions:
************************************************** ************
public static string Encrypt(string StringToEncrypt){
string EncryptedString;
UTF8Encoding utf8encoder = new UTF8Encoding();
byte[] inputInBytes = utf8encoder.GetBytes(StringToEncrypt);
TripleDESCryptoServiceProvider tdesProvider = new
TripleDESCryptoServiceProvider();
ICryptoTransform cryptoTransform =
tdesProvider.CreateEncryptor(tdeskey, tdesIV);
MemoryStream encryptedStream = new MemoryStream();
CryptoStream cryptStream = new CryptoStream(encryptedStream,
cryptoTransform, CryptoStreamMode.Write);
cryptStream.Write(inputInBytes, 0, inputInBytes.Length);
cryptStream.FlushFinalBlock();
encryptedStream.Position = 0;
byte[] result = new byte[encryptedStream.Length - 1];
encryptedStream.Read(result, 0, (int)(encryptedStream.Length - 1));
cryptStream.Close();
UTF8Encoding myutf = new UTF8Encoding();
EncryptedString = myutf.GetString(result);
return EncryptedString;
}//end Encrypt
public static string Decrypt(string StringToDecrypt){
string DecryptedString;
UTF8Encoding utf8encoder = new UTF8Encoding();
byte[] inputInBytes = utf8encoder.GetBytes(StringToDecrypt);
TripleDESCryptoServiceProvider tdesProvider = new
TripleDESCryptoServiceProvider();
ICryptoTransform cryptoTransform =
tdesProvider.CreateDecryptor(tdeskey, tdesIV);
MemoryStream decryptedStream = new MemoryStream();
CryptoStream cryptStream = new CryptoStream(decryptedStream,
cryptoTransform, CryptoStreamMode.Write);
cryptStream.Write(inputInBytes, 0, (inputInBytes.Length));
cryptStream.FlushFinalBlock();
decryptedStream.Position = 0;
byte[] result = new byte[decryptedStream.Length - 1];
decryptedStream.Read(result, 0, (int)(decryptedStream.Length - 1));
cryptStream.Close();
DecryptedString = result.ToString();
return DecryptedString;
}//end Decrypt
************************************************** **********************
cryptStream.FlushFinalBlock() in the decrypt function is what fails.
Any ideas would be greatly welcomed.
jdn
kingcrim@dotnet.itags.org.earthlink.netChange the stream type. The encryption samples use a file stream, but any
type of stream can be used to encrypt/decrypt. I have seen plenty of samples
with strings, as well as files, but you are correct that many of the samples
are file based.
Hope this helps.
--
Gregory A. Beamer
MPV; MCP: +I, SE, SD, DBA
************************************************** ********************
Think outside the box!
************************************************** ********************
"jdn" <kingcrim@.earthlink.net> wrote in message
news:uAMyKjEdDHA.904@.TK2MSFTNGP11.phx.gbl...
> I'm new to using this part of the framework, so I'm hoping I've done
> something obviously stupid, which someone will be able to point out in
> an obvious manner.
> Most of the samples I've seen involved encrypting and decrypting to and
> from a file, but that's not what I want. I want to be able to insert a
> string into an encryption function which outputs that encrypted string,
> which could then be sent into a decryption function and spit out the
> original string.
> As you might expect, ultimately, I want to be able to put this string
> into a database table.
> Anyways, I set up a simple test page where I enter a string in a
> textbox, and then run it through an encrypt, then decrypt, function, and
> print out to some labels to make sure it is doing it correctly.
> The encrypt part seems to work (at least the function doesn't fail), but
> the decrypt function fails, with an error saying that the length of the
> encrypted string is invalid. Here are the functions:
> ************************************************** ************
> public static string Encrypt(string StringToEncrypt){
> string EncryptedString;
> UTF8Encoding utf8encoder = new UTF8Encoding();
> byte[] inputInBytes = utf8encoder.GetBytes(StringToEncrypt);
> TripleDESCryptoServiceProvider tdesProvider = new
> TripleDESCryptoServiceProvider();
> ICryptoTransform cryptoTransform =
> tdesProvider.CreateEncryptor(tdeskey, tdesIV);
> MemoryStream encryptedStream = new MemoryStream();
> CryptoStream cryptStream = new CryptoStream(encryptedStream,
> cryptoTransform, CryptoStreamMode.Write);
> cryptStream.Write(inputInBytes, 0, inputInBytes.Length);
> cryptStream.FlushFinalBlock();
> encryptedStream.Position = 0;
> byte[] result = new byte[encryptedStream.Length - 1];
> encryptedStream.Read(result, 0, (int)(encryptedStream.Length - 1));
> cryptStream.Close();
> UTF8Encoding myutf = new UTF8Encoding();
> EncryptedString = myutf.GetString(result);
> return EncryptedString;
> }//end Encrypt
> public static string Decrypt(string StringToDecrypt){
> string DecryptedString;
>
> UTF8Encoding utf8encoder = new UTF8Encoding();
> byte[] inputInBytes = utf8encoder.GetBytes(StringToDecrypt);
> TripleDESCryptoServiceProvider tdesProvider = new
> TripleDESCryptoServiceProvider();
> ICryptoTransform cryptoTransform =
> tdesProvider.CreateDecryptor(tdeskey, tdesIV);
> MemoryStream decryptedStream = new MemoryStream();
> CryptoStream cryptStream = new CryptoStream(decryptedStream,
> cryptoTransform, CryptoStreamMode.Write);
> cryptStream.Write(inputInBytes, 0, (inputInBytes.Length));
> cryptStream.FlushFinalBlock();
> decryptedStream.Position = 0;
> byte[] result = new byte[decryptedStream.Length - 1];
> decryptedStream.Read(result, 0, (int)(decryptedStream.Length - 1));
> cryptStream.Close();
> DecryptedString = result.ToString();
> return DecryptedString;
> }//end Decrypt
> ************************************************** **********************
> cryptStream.FlushFinalBlock() in the decrypt function is what fails.
> Any ideas would be greatly welcomed.
> jdn
> kingcrim@.earthlink.net
Cowboy (Gregory A Beamer) wrote:
> Change the stream type. The encryption samples use a file stream, but any
> type of stream can be used to encrypt/decrypt. I have seen plenty of samples
> with strings, as well as files, but you are correct that many of the samples
> are file based.
> Hope this helps.
Change the stream type to what?
Thanks.
jdn
Cowboy (Gregory A Beamer) wrote:
> Change the stream type. The encryption samples use a file stream, but any
> type of stream can be used to encrypt/decrypt. I have seen plenty of samples
> with strings, as well as files, but you are correct that many of the samples
> are file based.
> Hope this helps.
Why would changing the stream type fix the issue? It seems to have to
do with how the decrypt function is written or maybe with how the
encrypt function writes the string.
jdn
There are several kinds of streams, IO streams, memory streams, XML streams.. etc.. so if you are dealing with a filestream - then you will only really be able to read/write from a file.. if you want to read/write to a variable, you likely need a MemoryStream or some equivalent..
"jdn" <kingcrim@.earthlink.net> wrote in message news:uTuNAWYdDHA.2932@.tk2msftngp13.phx.gbl...
Cowboy (Gregory A Beamer) wrote:
> Change the stream type. The encryption samples use a file stream, but any
> type of stream can be used to encrypt/decrypt. I have seen plenty of samples
> with strings, as well as files, but you are correct that many of the samples
> are file based.
>
> Hope this helps.
>
Why would changing the stream type fix the issue? It seems to have to
do with how the decrypt function is written or maybe with how the
encrypt function writes the string.
jdn
Drebin wrote:
> There are several kinds of streams, IO streams, memory streams, XML streams.. etc.. so if you are dealing with a filestream - then you will only really be able to read/write from a file.. if you want to read/write to a variable, you likely need a MemoryStream or some equivalent..
>
> "jdn" <kingcrim@.earthlink.net> wrote in message news:uTuNAWYdDHA.2932@.tk2msftngp13.phx.gbl...
> Cowboy (Gregory A Beamer) wrote:
>
>>Change the stream type. The encryption samples use a file stream, but any
>>type of stream can be used to encrypt/decrypt. I have seen plenty of samples
>>with strings, as well as files, but you are correct that many of the samples
>>are file based.
>>
>>Hope this helps.
>>
>
> Why would changing the stream type fix the issue? It seems to have to
> do with how the decrypt function is written or maybe with how the
> encrypt function writes the string.
> jdn
No, I know that. Since I am trying to Encrypt and Decrypt using
MemoryStream and CryptoStream both places, I don't see how changing that
will solve the issue. Though maybe I'm missing something.
Showing posts with label framework. Show all posts
Showing posts with label framework. Show all posts
Wednesday, March 28, 2012
TripleDES Encryption issue
Labels:
asp,
donesomething,
encryption,
framework,
net,
obviously,
point,
stupid,
tripledes
Monday, March 26, 2012
Trouble displaying Japanese text with aspx
Friends,
I am having trouble displaying Japanese text within a textbox (or
anywhere else) in an aspx page with .net 2.0 framework. Initial
default text in Japanese displays perfectly but when I attempt to
change the text following a button-click event, it displays as junk.
I have tried setting the globalization tag in the web.config file but
that does not help eiter.
<globalization requestEncoding="UTF-8" responseEncoding="UTF-8"
fileEncoding="UTF-8"/>
I should mention that the problem does not happen in my development pc
where I am using the Visual Web Developer 2005 IDE. It happens only
when I deploy the files to the actual IIS webserver on Windows 2000.
Would greatly appreciate any help.
Here's what I have:
1. TestJP.aspx contains:
<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true"
CodeFile="TestJP.aspx.cs" Inherits="TestJP" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Test JP</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtJP" runat="server" Height="101px"
Width="374px">Default Japanese Text</asp:TextBox>
<br />
<asp:Button ID="cmdJP" runat="server" Text="Change Text"
OnClick="cmdJP_Click" />
</div>
</form>
</body>
</html>
2. TestJP.aspx.cs contains:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class TestJP : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void cmdJP_Click(object sender, EventArgs e)
{
txtJP.Text = "New Japanese text";
}
}On May 8, 9:16 am, pardesiya <zenst...@.gmail.com> wrote:
> Friends,
> I am having trouble displaying Japanese text within a textbox (or
> anywhere else) in an aspx page with .net 2.0 framework. Initial
> default text in Japanese displays perfectly but when I attempt to
> change the text following a button-click event, it displays as junk.
> I have tried setting the globalization tag in the web.config file but
> that does not help eiter.
> <globalization requestEncoding="UTF-8" responseEncoding="UTF-8"
> fileEncoding="UTF-8"/>
> I should mention that the problem does not happen in my development pc
> where I am using the Visual Web Developer 2005 IDE. It happens only
> when I deploy the files to the actual IIS webserver on Windows 2000.
> Would greatly appreciate any help.
> Here's what I have:
> 1. TestJP.aspx contains:
> <%@. Page Language="C#" AutoEventWireup="true"
> CodeFile="TestJP.aspx.cs" Inherits="TestJP" %>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www
.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml" >
> <head runat="server">
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
> <title>Test JP</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
> <asp:TextBox ID="txtJP" runat="server" Height="101px"
> Width="374px">Default Japanese Text</asp:TextBox>
> <br />
> <asp:Button ID="cmdJP" runat="server" Text="Change Text"
> OnClick="cmdJP_Click" />
> </div>
> </form>
> </body>
> </html>
> 2. TestJP.aspx.cs contains:
> using System;
> using System.Data;
> using System.Configuration;
> using System.Collections;
> using System.Web;
> using System.Web.Security;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.Web.UI.WebControls.WebParts;
> using System.Web.UI.HtmlControls;
> public partial class TestJP : System.Web.UI.Page
> {
> protected void Page_Load(object sender, EventArgs e)
> {
> }
> protected void cmdJP_Click(object sender, EventArgs e)
> {
> txtJP.Text = "New Japanese text";
> }
>
> }- Hide quoted text -
> - Show quoted text -
Go to File - Save .aspx As - point to Save and select Save with
Encoding... What encoding do you use to save the file?
On May 8, 9:30 am, Alexey Smirnov <alexey.smir...@.gmail.com> wrote:
> Go to File - Save .aspx As - point to Save and select Save with
> Encoding... What encoding do you use to save the file... Hide quoted text -
>
Wait... you have to check the encoding for your TestJP.aspx.cs file.
It seems that it saved in a different encoding...
Alexey thanks a lot for your prompt suggestion. That worked!
TestJP.aspx.cs and TestJP.aspx were saved with Shift_JIS. Changed
that to UTF-8 and it works fine!
I have a second question which is related. I query data into a dataset
and display the result in the same text box but it appears junk. Is
there any way I should set the charset of the DataSet? The database is
probably encoded with Unicode.
DataSet dsTables = new DataSet();
dsTables = <code to get data from database>
txtJP.Text = dsTables.Tables[0].Rows[0]["japanese_name"].ToString();
using System.Data.OleDb;
On May 8, 10:32 am, pardesiya <zenst...@.gmail.com> wrote:
> Alexey thanks a lot for your prompt suggestion. That worked!
> TestJP.aspx.cs and TestJP.aspx were saved with Shift_JIS. Changed
> that to UTF-8 and it works fine!
> I have a second question which is related. I query data into a dataset
> and display the result in the same text box but it appears junk. Is
> there any way I should set the charset of the DataSet? The database is
> probably encoded with Unicode.
> DataSet dsTables = new DataSet();
> dsTables = <code to get data from database>
> txtJP.Text = dsTables.Tables[0].Rows[0]["japanese_name"].ToString();
Where data came from? Did you do that from your asp.net application?
It seems that the data encoded in other format...
Try to change encoding of your result page, in IE right click,
Encoding - Shift_JIS (or any other)
Thanks Alexey. Yes, I'm getting the data from asp.net application.
But changing the encoding in IE doesnt seem to help. As you mention
maybe the data is encoded differently. Probably I should post this as
a separate thread.
using System.Data.OleDb;
OleDbConnection OledbConn = new OleDbConnection();
OleDbDataAdapter OledbDataAdap = new OleDbDataAdapter();
DataSet OleDbDS = new DataSet();
OledbConn.ConnectionString = <connection string to Sybase
database>;
OledbConn.Open();
OledbDataAdap.SelectCommand = new OleDbCommand("select
japanese_name from ... ", OledbConn);
OledbDataAdap.Fill(OleDbDS);
OledbConn.Close();
return OleDbDS;
On May 8, 11:06 am, pardesiya <zenst...@.gmail.com> wrote:
> Thanks Alexey. Yes, I'm getting the data from asp.net application.
> But changing the encoding in IE doesnt seem to help. As you mention
> maybe the data is encoded differently. Probably I should post this as
> a separate thread.
> using System.Data.OleDb;
> OleDbConnection OledbConn = new OleDbConnection();
> OleDbDataAdapter OledbDataAdap = new OleDbDataAdapter();
> DataSet OleDbDS = new DataSet();
> OledbConn.ConnectionString = <connection string to Sybase
> database>;
> OledbConn.Open();
> OledbDataAdap.SelectCommand = new OleDbCommand("select
> japanese_name from ... ", OledbConn);
> OledbDataAdap.Fill(OleDbDS);
> OledbConn.Close();
> return OleDbDS;
Sorry, I think I was not clear. I'm interesting in the code which
stored the data in the database. I guess, you have a kind of web form
with fields and submit button which fires the code-behind action. This
form has to be in UTF encoded
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
not sure about a code (want to see it first)
and your database should support that encoding.
Actually, if you browse the database using a shell, do you see the
correct characters? Are you able to insert any data in Japanese (using
a shell) and see that text on the website?
Ok I understand what you mean. Actually I am not sure about how the
data is stored in the database. The people who maintain the database
have some kind of tool or database application to insert the data. I
only try to retrieve some data using an oledb connection in my asp.net
form.
But I am able to browse the database using Microsoft Query and see the
Japanese data correctly. I can even download the correct data into
Excel. I dont have permission to insert data so cannot check that
part.
On May 8, 11:50 am, pardesiya <zenst...@.gmail.com> wrote:
> Ok I understand what you mean. Actually I am not sure about how the
> data is stored in the database. The people who maintain the database
> have some kind of tool or database application to insert the data. I
> only try to retrieve some data using an oledb connection in my asp.net
> form.
> But I am able to browse the database using Microsoft Query and see the
> Japanese data correctly. I can even download the correct data into
> Excel. I dont have permission to insert data so cannot check that
> part.
1. Check the existing output. Maybe it will give you idea about
encoding.
2. Try to encode
System.Text.Encoding en1 = System.Text.Encoding.Unicode;
System.Text.Encoding en2 = System.Text.Encoding.UTF8;
txtJP.Text = en2.GetString(en1.GetBytes(dsTables.Tables[0].Rows[0]
["japanese_name"].ToString()));
or
System.Text.Encoding en1 =
System.Text.Encoding.Encoding.GetEncoding("Shift_JIS"); // or any
other standard JP-encoding
System.Text.Encoding en2 = System.Text.Encoding.UTF8;
txtJP.Text = en2.GetString(en1.GetBytes(dsTables.Tables[0].Rows[0]
["japanese_name"].ToString()));
3. Check code page of your database
4. Contact db-developers :-)
I am having trouble displaying Japanese text within a textbox (or
anywhere else) in an aspx page with .net 2.0 framework. Initial
default text in Japanese displays perfectly but when I attempt to
change the text following a button-click event, it displays as junk.
I have tried setting the globalization tag in the web.config file but
that does not help eiter.
<globalization requestEncoding="UTF-8" responseEncoding="UTF-8"
fileEncoding="UTF-8"/>
I should mention that the problem does not happen in my development pc
where I am using the Visual Web Developer 2005 IDE. It happens only
when I deploy the files to the actual IIS webserver on Windows 2000.
Would greatly appreciate any help.
Here's what I have:
1. TestJP.aspx contains:
<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true"
CodeFile="TestJP.aspx.cs" Inherits="TestJP" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Test JP</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtJP" runat="server" Height="101px"
Width="374px">Default Japanese Text</asp:TextBox>
<br />
<asp:Button ID="cmdJP" runat="server" Text="Change Text"
OnClick="cmdJP_Click" />
</div>
</form>
</body>
</html>
2. TestJP.aspx.cs contains:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class TestJP : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void cmdJP_Click(object sender, EventArgs e)
{
txtJP.Text = "New Japanese text";
}
}On May 8, 9:16 am, pardesiya <zenst...@.gmail.com> wrote:
> Friends,
> I am having trouble displaying Japanese text within a textbox (or
> anywhere else) in an aspx page with .net 2.0 framework. Initial
> default text in Japanese displays perfectly but when I attempt to
> change the text following a button-click event, it displays as junk.
> I have tried setting the globalization tag in the web.config file but
> that does not help eiter.
> <globalization requestEncoding="UTF-8" responseEncoding="UTF-8"
> fileEncoding="UTF-8"/>
> I should mention that the problem does not happen in my development pc
> where I am using the Visual Web Developer 2005 IDE. It happens only
> when I deploy the files to the actual IIS webserver on Windows 2000.
> Would greatly appreciate any help.
> Here's what I have:
> 1. TestJP.aspx contains:
> <%@. Page Language="C#" AutoEventWireup="true"
> CodeFile="TestJP.aspx.cs" Inherits="TestJP" %>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www
.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <html xmlns="http://www.w3.org/1999/xhtml" >
> <head runat="server">
> <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
> <title>Test JP</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <div>
> <asp:TextBox ID="txtJP" runat="server" Height="101px"
> Width="374px">Default Japanese Text</asp:TextBox>
> <br />
> <asp:Button ID="cmdJP" runat="server" Text="Change Text"
> OnClick="cmdJP_Click" />
> </div>
> </form>
> </body>
> </html>
> 2. TestJP.aspx.cs contains:
> using System;
> using System.Data;
> using System.Configuration;
> using System.Collections;
> using System.Web;
> using System.Web.Security;
> using System.Web.UI;
> using System.Web.UI.WebControls;
> using System.Web.UI.WebControls.WebParts;
> using System.Web.UI.HtmlControls;
> public partial class TestJP : System.Web.UI.Page
> {
> protected void Page_Load(object sender, EventArgs e)
> {
> }
> protected void cmdJP_Click(object sender, EventArgs e)
> {
> txtJP.Text = "New Japanese text";
> }
>
> }- Hide quoted text -
> - Show quoted text -
Go to File - Save .aspx As - point to Save and select Save with
Encoding... What encoding do you use to save the file?
On May 8, 9:30 am, Alexey Smirnov <alexey.smir...@.gmail.com> wrote:
> Go to File - Save .aspx As - point to Save and select Save with
> Encoding... What encoding do you use to save the file... Hide quoted text -
>
Wait... you have to check the encoding for your TestJP.aspx.cs file.
It seems that it saved in a different encoding...
Alexey thanks a lot for your prompt suggestion. That worked!
TestJP.aspx.cs and TestJP.aspx were saved with Shift_JIS. Changed
that to UTF-8 and it works fine!
I have a second question which is related. I query data into a dataset
and display the result in the same text box but it appears junk. Is
there any way I should set the charset of the DataSet? The database is
probably encoded with Unicode.
DataSet dsTables = new DataSet();
dsTables = <code to get data from database>
txtJP.Text = dsTables.Tables[0].Rows[0]["japanese_name"].ToString();
using System.Data.OleDb;
On May 8, 10:32 am, pardesiya <zenst...@.gmail.com> wrote:
> Alexey thanks a lot for your prompt suggestion. That worked!
> TestJP.aspx.cs and TestJP.aspx were saved with Shift_JIS. Changed
> that to UTF-8 and it works fine!
> I have a second question which is related. I query data into a dataset
> and display the result in the same text box but it appears junk. Is
> there any way I should set the charset of the DataSet? The database is
> probably encoded with Unicode.
> DataSet dsTables = new DataSet();
> dsTables = <code to get data from database>
> txtJP.Text = dsTables.Tables[0].Rows[0]["japanese_name"].ToString();
Where data came from? Did you do that from your asp.net application?
It seems that the data encoded in other format...
Try to change encoding of your result page, in IE right click,
Encoding - Shift_JIS (or any other)
Thanks Alexey. Yes, I'm getting the data from asp.net application.
But changing the encoding in IE doesnt seem to help. As you mention
maybe the data is encoded differently. Probably I should post this as
a separate thread.
using System.Data.OleDb;
OleDbConnection OledbConn = new OleDbConnection();
OleDbDataAdapter OledbDataAdap = new OleDbDataAdapter();
DataSet OleDbDS = new DataSet();
OledbConn.ConnectionString = <connection string to Sybase
database>;
OledbConn.Open();
OledbDataAdap.SelectCommand = new OleDbCommand("select
japanese_name from ... ", OledbConn);
OledbDataAdap.Fill(OleDbDS);
OledbConn.Close();
return OleDbDS;
On May 8, 11:06 am, pardesiya <zenst...@.gmail.com> wrote:
> Thanks Alexey. Yes, I'm getting the data from asp.net application.
> But changing the encoding in IE doesnt seem to help. As you mention
> maybe the data is encoded differently. Probably I should post this as
> a separate thread.
> using System.Data.OleDb;
> OleDbConnection OledbConn = new OleDbConnection();
> OleDbDataAdapter OledbDataAdap = new OleDbDataAdapter();
> DataSet OleDbDS = new DataSet();
> OledbConn.ConnectionString = <connection string to Sybase
> database>;
> OledbConn.Open();
> OledbDataAdap.SelectCommand = new OleDbCommand("select
> japanese_name from ... ", OledbConn);
> OledbDataAdap.Fill(OleDbDS);
> OledbConn.Close();
> return OleDbDS;
Sorry, I think I was not clear. I'm interesting in the code which
stored the data in the database. I guess, you have a kind of web form
with fields and submit button which fires the code-behind action. This
form has to be in UTF encoded
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
not sure about a code (want to see it first)
and your database should support that encoding.
Actually, if you browse the database using a shell, do you see the
correct characters? Are you able to insert any data in Japanese (using
a shell) and see that text on the website?
Ok I understand what you mean. Actually I am not sure about how the
data is stored in the database. The people who maintain the database
have some kind of tool or database application to insert the data. I
only try to retrieve some data using an oledb connection in my asp.net
form.
But I am able to browse the database using Microsoft Query and see the
Japanese data correctly. I can even download the correct data into
Excel. I dont have permission to insert data so cannot check that
part.
On May 8, 11:50 am, pardesiya <zenst...@.gmail.com> wrote:
> Ok I understand what you mean. Actually I am not sure about how the
> data is stored in the database. The people who maintain the database
> have some kind of tool or database application to insert the data. I
> only try to retrieve some data using an oledb connection in my asp.net
> form.
> But I am able to browse the database using Microsoft Query and see the
> Japanese data correctly. I can even download the correct data into
> Excel. I dont have permission to insert data so cannot check that
> part.
1. Check the existing output. Maybe it will give you idea about
encoding.
2. Try to encode
System.Text.Encoding en1 = System.Text.Encoding.Unicode;
System.Text.Encoding en2 = System.Text.Encoding.UTF8;
txtJP.Text = en2.GetString(en1.GetBytes(dsTables.Tables[0].Rows[0]
["japanese_name"].ToString()));
or
System.Text.Encoding en1 =
System.Text.Encoding.Encoding.GetEncoding("Shift_JIS"); // or any
other standard JP-encoding
System.Text.Encoding en2 = System.Text.Encoding.UTF8;
txtJP.Text = en2.GetString(en1.GetBytes(dsTables.Tables[0].Rows[0]
["japanese_name"].ToString()));
3. Check code page of your database
4. Contact db-developers :-)
Labels:
asp,
aspx,
displaying,
framework,
friends,
initialdefault,
japanese,
net,
oranywhere,
page,
text,
textbox,
trouble
Saturday, March 24, 2012
Trouble updating version to 1.1
Having trouble getting the my.net framework to version 1.1 I downloaded it, ran the setup.exe, and restarted. I open up my visual stud .net and it says 1.0. Please helpVS.NET 2002 will only work with 1.0 of the framework, and VS.NET 2003 will only work with the 1.1 framework. Does that give you an idea of whats wrong.
I thought you were able to update the framework. Anyway, I guess that would be the problem then. So, there is no way I can share projects that are created in vs.net 2003 using vs.net 2002. For instance, "arParams[0] = new SqlParameter("@.RegionId", ddlRegion.SelectedValue);" does not work in 2002, but does in 2003... .selectedValue is an issue.
You can install different frameworks, but VS.NET 2002 and VS.NET 2003 cannot switch between the different frameworks.
I thought you were able to update the framework. Anyway, I guess that would be the problem then. So, there is no way I can share projects that are created in vs.net 2003 using vs.net 2002. For instance, "arParams[0] = new SqlParameter("@.RegionId", ddlRegion.SelectedValue);" does not work in 2002, but does in 2003... .selectedValue is an issue.
You can install different frameworks, but VS.NET 2002 and VS.NET 2003 cannot switch between the different frameworks.
Your assumption is correct, there is no way of doing what you wish if you want to code against the 1.0 framework (using VS.NET 2002).
so i have to buy vs.net 2003 to view these projects?
Well, yes and no. To get the full IDE experience, I'd say yes. But, you can do command line compilations, if you wish.
Subscribe to:
Posts (Atom)