convert System.Byte[]" inot String

Posted by Sagarp under ASP.NET on 12/3/2009 | Views : 7091 | Status : [Member] | Replies : 5
HI
i have convert System.Byte[]" inot String

this my code

// button click//
SqlCommand cmd = new SqlCommand();
SqlConnection sqlconn = new SqlConnection("Data Source=localhost;Initial Catalog=WSS_SSP_Content;Integrated Security=True");
sqlconn.Open();
DirectoryEntry rootEntry = new DirectoryEntry("LDAP://DC=domain,DC=com", "administrator", "abc123");
string ldap = rootEntry.Path;
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM OpenQuery(ADSI, 'SELECT whenCreated,objectGUID FROM ''" + ldap + "'' WHERE objectClass=''User''')", sqlconn);
DataSet ds = new DataSet();
da.Fill(ds);


foreach (DataRow dr in ds.Tables[0].Rows)
{
String pid = Convert.ToString(dr[0]);
cmd.Connection = sqlconn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "exec proc_insert '" + dr[0] + "','" + dr[1] + "',1,0,0,'Insert'";
cmd.ExecuteNonQuery();

}
thanks
sagar

Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/



Responses

Posted by: Vuyiswamb on: 12/3/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down

The First line is not Correct, it will not compile in C#


System.Byte[] pid=0xDB0F60B41150314082A1EC9A56200902;


Byte is to small for it, you should use a String to Carry it and you will not need to Convert it later, or mybe i dont understand your problem , but it will seem you dont understand what you are doing.

Thank you for Posting at DotnetFunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Sagarp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Vuyiswamb on: 12/4/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
Which line are you having a Problem and what is your Problem? Please Dont Edit this message just reply.

Thank you for posting at dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Sagarp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sagarp on: 12/4/2009 [Member] Bronze

Up
0
Down
objectGUID i will string format but when i will fire query i got output System.Byte[]"

Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/

Sagarp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhi2434 on: 12/4/2009 [Member] [Microsoft_MVP] [MVP] Silver

Up
0
Down
Use :

byte[] bytearray = content;
string str = Encoding.Default.GetString(bytearray);


If you need to convert a string to bytearray use

bytearray = Encoding.Default.GetBytes(str);


:)

www.abhisheksur.com

Sagarp, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sagarp on: 12/4/2009 [Member] Bronze

Up
0
Down
thx abhi

Thanks
SagarP
http://www.emanonsolutions.net
http://emanonsolutions.blogspot.com/

Sagarp, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response