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 1097061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:22:28+00:00 2026-05-17T00:22:28+00:00

I’m not really used to C# sharp but have used VB.NET before. I’m needing

  • 0

I’m not really used to C# sharp but have used VB.NET before.

I’m needing to set the value of text fields, dropdowns etc from data from a query. To enter the data I have been using a class Computer with the method saveComputer() that takes values from user controls. Now I want an edit page that uses the id from url & uses getComputer(id) from Computer class and returns the values to be set to the user controls. I’m unsure about using this method to set the control values.

Edit.aspx.cs

 protected void btnSave_Click(object sender, EventArgs e)
    {
        int id = 3; //will be replaced to GET value
        Computer comp = new Computer();
        //comp.updateComputer(ref id);

    }

My Computer class

public getComputer(ref int id)
    {
        DataSet data = new DataSet();
        using (SqlConnection conn = new SqlConnection(
               "Server=JURA;Database=ReadyForSeven;User id=;Password="))
        {
            String sql = "SELECT * FROM computers WHERE id=@id";

            //replace contatenation of variable with parameter name


            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandText = sql.ToString();
            cmd.CommandType = CommandType.Text;

            //Define SqlParameter object and assign value to the parameter

            cmd.Parameters.Add("@id", SqlDbType.Int);
            cmd.Parameters["@id"].Value = id;

            try
            {
                using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                {
                    da.Fill(data);
                    // return data here
                }
            }
            catch (SqlException ex)
            {
                //send user to error page and log message

            }
        }
    }

So what I’m wanting to achieve is using the getcomputer method of Computer to set the values of the controls on Edit.aspx

Can anyone help me out?

  • 1 1 Answer
  • 1 View
  • 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-05-17T00:22:29+00:00Added an answer on May 17, 2026 at 12:22 am

    You’ll need to modify your getComputer method to return a DataSet like:

    public DataSet getComputer(int id) {
    

    Once that’s done we can call it and populate the form controls on the page load with something like:

    protected void Page_Load(object sender, EventArgs e) {
        if (!IsPostBack) {
            int id = 3; // get from querystring
            DataSet ds = getComputer(id);
            DataRow dr = ds.Tables[0].Rows[0]; // get the first row returned
    
            // populate form controls
            txtFirstName.Text = dr["FirstName"].ToString();
            ddlState.SelectedValue = dr["State"].ToString();
        }
    }
    

    Below is an updated version of getComputer that will always return a value and is a little tighter:

    public DataSet getComputer(int id) // you don't need to pass int by ref unless you're planning on changing it inside this method
    {
        DataSet data = new DataSet();
        using (SqlConnection conn = new SqlConnection("Server=JURA;Database=ReadyForSeven;User id=;Password=")) {
            using (SqlCommand cmd = new SqlCommand("SELECT * FROM computers WHERE id = @id", conn)) {
                cmd.Parameters.AddWithValue("id", id);
                using (SqlDataAdapter da = new SqlDataAdapter(cmd)) {
                    da.Fill(data);
                    return data;
                }
            }
        }
    }
    

    I had to remove the try/catch blog to ensure the method always returned a value. If you absolutely need the try/catch block you’ll need to return an empty DataSet at the end of the method to get to compile correctly.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.