Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7856865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:50:32+00:00 2026-06-02T20:50:32+00:00

I have the following code which assigns values to a datarow and and adds

  • 0

I have the following code which assigns values to a datarow and and adds to the datatable. I want to write function which returns a datarow which enables me to write less code. Please check the code below and provide me any suggestions

            objRow = dtTODO.NewRow
            objRow.Item("Item") = "Test"
            objRow.Item("Message") = "Test"
            objRow.Item("ButtonText") = "Add"
            dtTODO.Rows.Add(objRow)

            objRow = dtTODO.NewRow
            objRow.Item("Item") = "Test2"
            objRow.Item("Message") = "Test2"
            objRow.Item("ButtonText") = "Add"
            dtTODO.Rows.Add(objRow)

Assume that I am adding the above records. I want to create a function which returns a datarow as,

Public Function ItemRow(ByVal strItem As String, ByVal strMessage As String, ByVal strButtonText As String, ByVal strUrl As String) As DataRow

End Function

And add this as,

dtTODO.Rows.Add(ItemRow(item, msg,bttext,url))

Hope I am not confusing too much :).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T20:50:34+00:00Added an answer on June 2, 2026 at 8:50 pm

    You function signature seems ok only You have to pass the dtTODO.Newrow reference to the function as well.

    Try this:

    AddRow("a", "b", "c", dtTODO);
    AddRow("a", "b", "c", dtTODO);
    
    void AddRow(string str1, string str2, string str3, DataTable dt)
    {
            DataRow objRow = dtTODO.NewRow();
            objRow["Item"] = str1;
            objRow["Message"] = str2;
            objRow["ButtonText"] = str3;
            dt.Rows.Add(objRow);
    }
    

    You can get much better code as well.

    Please convert the above code to VB

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to know is below code correct ? I have following code which
I have following code which works for radio buttons but need to be changed
I have the following code which should put programs startable in Bash. if [
I have the following code which reads in the follow file, append a \r\n
I have the following code which re-uses a CookieContainer which logs in on the
I have the following code which I stripped out of any non-essential lines to
I have the following code which ends up forever reading '/proc/cpuinfo' as it keeps
I have the following code which lets the user plot two points on a
I have the following code which redirect pages depends on $path. ... $path =
I have the following code which is in a transaction. I'm not sure where/when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.