none
Need help with string array's and byte array's RRS feed

  • Question

  • Hello,

    I have a method, to get data and send to a text box.

    But what I get in the text box for a string array is:

    System string []

    And what I get in the text box for a byte array is:

    System byte []

    Here is the method I'm using:

    public virtual DataSet GetDataSet()
    {
    	this.VerifyName();
    	string[] sectionNames = this.GetSectionNames();
    	if (sectionNames == null)
    	{
    		return null;
    	}
    	DataSet dataSet = new DataSet(this.Name);
    	string[] strArrays = sectionNames;
    	for (int i = 0; i < (int)strArrays.Length; i++)
    	{
    		string str = strArrays[i];
    		DataTable dataTable = dataSet.Tables.Add(str);
    		string[] entryNames = this.GetEntryNames(str);
    		DataColumn[] dataColumn = new DataColumn[(int)entryNames.Length];
    		object[] objArray = new object[(int)entryNames.Length];
    		int num = 0;
    		string[] strArrays1 = entryNames;
    		for (int j = 0; j < (int)strArrays1.Length; j++)
    		{
    			string str1 = strArrays1[j];
    			object value = this.GetValue(str, str1);
    			dataColumn[num] = new DataColumn(str1, value.GetType());
    			int num1 = num;
    			num = num1 + 1;
    			objArray[num1] = value;
    		}
    		dataTable.Columns.AddRange(dataColumn);
    		dataTable.Rows.Add(objArray);
    	}
    	return dataSet;
    }

    Any help on what I need to change will be great

    Thank you

    Joe Essex


    • Edited by Joe Essex Wednesday, November 7, 2018 12:33 PM
    Wednesday, November 7, 2018 12:24 PM

All replies

  • Myself, I would have used a List<string> with a simple foreach loop.

    https://www.dotnetperls.com/string-list

    Wednesday, November 7, 2018 1:04 PM
  • Where in this code is there a byte array?

    Why do you make copies of things?  "strArrays", "strArrays1" and "num1" are all totally unnecessary.


    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    Wednesday, November 7, 2018 10:00 PM
  • The reason for the copies, is that it returns several different values, to  several different text box's

    I know there is no byte array, that's the problem. The method above bring strings back

    to the text box. But it doesn't bring Multi Strings or Binary back to the text box.

    I was wanting to know what to change so it will.

    I might be showing the wrong method, so here are a couple more

    public virtual int GetValue(string section, string entry, int defaultValue)
    {
    	int num;
    	object value = this.GetValue(section, entry);
    	if (value == null)
    	{
    		return defaultValue;
    	}
    	try
    	{
    		num = Convert.ToInt32(value);
    	}
    	catch
    	{
    		num = 0;
    	}
    	return num;
    }
    
    public virtual double GetValue(string section, string entry, double defaultValue)
    {
    	double num;
    	object value = this.GetValue(section, entry);
    	if (value == null)
    	{
    		return defaultValue;
    	}
    	try
    	{
    		num = Convert.ToDouble(value);
    	}
    	catch
    	{
    		num = 0;
    	}
    	return num;
    }

    Here is an int return, and a double return

    I just cant figure out the String array one

    or the byte array one



    • Edited by Joe Essex Thursday, November 8, 2018 6:08 AM
    Thursday, November 8, 2018 5:39 AM
  • Hi, Joe Essex,

    Thank you for posting here.

    For your question, I need to confirm come questions with you.
    1. The GetDataSet method has some definitions you do not provided. We could not test the code, please provide more details.
    2. The GetValue method uses only 2 parameters.

    object value = this.GetValue(section, entry);

    But, it defined with 3 parameters.

    public virtual int GetValue(string section, string entry, int defaultValue){…}

    3. How do you call the GetDataSet method to get a string or a byte array.

    Best regards,
    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, November 8, 2018 8:03 AM
    Moderator
  • Hi Joe Essex,

    Thank you for posting here.

    I have check the link you provided. The OneDrive link is empty. Please check again. We are waiting for your details.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 9, 2018 7:09 AM
    Moderator
  • Hi Joe Essex,

    You could verify your account in the link below.

    https://social.msdn.microsoft.com/Forums/en-US/dc4002e4-e3de-4b1e-9a97-3702387886cc/verify-account-42?forum=reportabug

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, November 9, 2018 8:14 AM
    Moderator
  • Hi Joe Essex,

    I check the two links you provided. It is still empty.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, November 9, 2018 8:24 AM
    Moderator
  • Hello All,

            I am re-submitting the link to my project.

    I am trying to get the values of Multi- strings and Binary.

    When I click on the entry of the section then in the values drop down list,

    for a multi string, it should show (string[])value.

    for a Binary, it should show (byte)value

    .LINK:

    Registry Utility




    • Edited by Joe Essex Thursday, February 14, 2019 12:13 AM
    Wednesday, November 14, 2018 5:26 PM