vb.net web form using string and unique objects RRS feed

  • Question

  • User-127506019 posted
    In a vb.net 2010 web form  application, I am trying to determine the best way to accomplish this goal.
    Write now 1 letter is generated and sent to one guardian. However this application needs to be
    changed so that the same exact letter can be send to different mailing addresses since each studnet
    may have more than one parent/guardian at different mailing addresses. So basically I want to generate
    more than one letter with the same wording. The only differences between the letters would be the mailing
    addresses. I want the letters to be written to the same varchar(max) column in a sql server 2012
    database. The letters will be in the same field since the data will be sent to a sql server reporting
    server where the letters will be generated one after each other.
    Right now the letters are written to the 'Dim _al As Letters = New Letters()' object. The only way I know to modify
    text data is to use a string or stringbuilder objects. I do not know yo modify data is other objects. Basically I
    want to use a string.replace logic to replace the addresses in the second letter. I also want to use
    stringbuilder.append to place more than one letter following another to be placed in the osne varchar(max)
    I know I can use the following code to convert a custom object to a string.
     Dim _LetterStr As String = String.Empty
     Dim _LetterStrbldr As StringBuilder = New StringBuilder
     _LetterStr = _Letter.Letter.ToString()

    However I do not know how to convert a string object back to a custom object.

    Here is the original code of the application:

    #Region "Protected Sub btnSubmitModifiedLetter_Click(ByVal sender As Object, 
    ByVal e As System.EventArgs) Handles btnSubmitModifiedLetter.Click" 
        Protected Sub btnSubmitModifiedLetter_Click(ByVal sender As Object, ByVal e 
    As System.EventArgs) Handles btnSubmitModifiedLetter.Click 
            Dim _al As Letters = New Letters() 
            Dim _infinteCampusText As String 
            Dim _Letter As Letter = New Letter() 
            Dim _startDate As DateTime = Now() 
            Dim _term As Integer = 0        
            _Letter.SchoolYear = _schoolyear 
            _Letter.Term = _term 
            _Letter.Milestone = ddlMilestone.SelectedValue 
            _Letter.SchoolNumber = Right("000" & ddlSchools.SelectedValue,3) 
            _Letter.Printed = "Y" 
            _Letter.Letter = reLetterEditor.Content 
            _Letter.StudentLink = Right("0000000" & txtStuLink.Text, 7) 
            _Letter.Language = txtLanguage.Text 
            _infinteCampusText = _al.BuildText(_Letter)   
            _al.InsertData(_Letter, _infinteText) 
            btnProcessSelections.Visible = False 
            gvLetters.DataSourceID = String.Empty 
            gvLetters.Visible = False 
            Response.Redirect("letter.aspx?schoolyear=" + 
    _Letter.SchoolYear.ToString() + "&schoolnum=" + 
    _Letter.SchoolNumber.ToString() + "&term=" + 
    _Letter.Term.ToString() + "&milestonecode=" + 
    _Letter.Milestone.ToString() + "&startdate=" + _startDate.ToString() + 
    "&enddate=" + DateAdd(DateInterval.Day, 1, Today()).ToString() + 
        End Sub 
    #End Region 

    Thus can you show me the code to convert a string object to a custom object and/or show me code on how to accomplish my goal?

    Saturday, November 19, 2016 4:06 AM


  • User-1838255255 posted

    Hi peggy_girl,

    According to your description, as far as I know, you can use JSON string, .NET provide method convert JSON string  to custom class object. Here is sample code:

    public class User
                public User(string json)
                    JObject jObject = JObject.Parse(json);
                    JToken jUser = jObject["user"];
                    name = (string)jUser["name"];
                    teamname = (string)jUser["teamname"];
                    email = (string)jUser["email"];
                    players = jUser["players"].ToArray();
                public string name { get; set; }
                public string teamname { get; set; }
                public string email { get; set; }
                public Array players { get; set; }
            // Use
            private void Run()
                string json = @"{""user"":{""name"":""asdf"",""teamname"":""b"",""email"":""c"",""players"":[""1"",""2""]}}";
                User user = new User(json);
                Response.Write("Name : " + user.name);
                Response.Write("Teamname : " + user.teamname);
                Response.Write("Email : " + user.email);
                foreach (var player in user.players)

    Best Regards,

    Eric Du

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 22, 2016 2:32 AM