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

  • Home
  • SEARCH
  • 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 4583074
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:09:51+00:00 2026-05-21T21:09:51+00:00

I want the user entered values to get displayed in the form again.. my

  • 0

I want the user entered values to get displayed in the form again.. my values get entered into the SQL Server database, but I don’t know how to retrieve the values again in the form.. my code is:

SqlDataReader rdr = null;
SqlConnection conn = new SqlConnection("Data Source=Si-6\\SQLSERVER2005;Initial Catalog=emp;Integrated Security=SSPI");

try
{
   conn.Open();

   SqlCommand cmd=new SqlCommand ("insert into timeday(project,iteration,activity,description,status,hour)values('"+this .name1 .SelectedValue +"','"+this .iteration .SelectedValue +"','"+this .activity .SelectedValue +"','"+this.name2.Text+"','"+this.status .SelectedValue +"','"+this .Text1 .Text +"')",conn );

   rdr = cmd.ExecuteReader();

   while (rdr.Read())
   {
      Console.WriteLine(rdr[0]);
   }
}
finally
{
   if (rdr != null)
      rdr.Close();

   if (conn != null)
      conn.Close();
}
  • 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-05-21T21:09:52+00:00Added an answer on May 21, 2026 at 9:09 pm

    You should:

    • avoid SQL injection and don’t just concatenate together your SQL statements! Use parametrized queries instead!
    • put your SqlConnection and SqlCommand objects into using blocks
    • when you want to call an INSERT statement, definitely do not call .ExecuteReader() on your SqlCommand – use .ExecuteNonQuery() instead…

    Try something like this:

    string connStr = "Data Source=Silverage-6\\SQLSERVER2005;Initial Catalog=emp;Integrated Security=SSPI";
    
    string queryStmt = 
       "INSERT INTO dbo.timeday(project, iteration, activity, description, status, hour) " + 
       "VALUES(@Project, @Iteration, @Activity, @Description, @Status, @Hour)";
    
    using(SqlConnection conn = new SqlConnection())
    using(SqlCommand _cmd = new SqlCommand(queryStmt, conn))
    {
       _cmd.Parameters.Add("@Project", SqlDbType.VarChar, 100);
       _cmd.Parameters["@Project"].Value = this.name1.SelectedValue.Trim();
    
       // add other parameters the same way....
    
       conn.Open();
       int result = _cmd.ExecuteNonQuery();
       conn.Close();
    }
    

    It would be even better if you:

    • would retrieve the connection string from a config file once, centrally, and just pass it into this method
    • would retrieve the values to set from your web UI in your UI code, and then call this business method on a business logic object and pass in the values you’ve determined

    Right now, you’re wildly mixing UI code (retrieving the values from the dropdowns and textboxes) with database/business logic code – this is not a very solid design…..

    Update: if you want to retrieve values and display them, you can use something like this:

    public DataTable GetDataForProject(string projectName)
    {
       string connStr = "Data Source=Silverage-6\\SQLSERVER2005;Initial Catalog=emp;Integrated Security=SSPI";
    
       string queryStmt = 
          "SELECT project, iteration, activity, description, status, hour " + 
          "FROM dbo.timeday " + 
          "WHERE project = @project";
    
       DataTable resultTable = new DataTable();
    
       using(SqlConnection conn = new SqlConnection())
       using(SqlCommand _cmd = new SqlCommand(queryStmt, conn))
       {
          _cmd.Parameters.Add("@Project", SqlDbType.VarChar, 100);
          _cmd.Parameters["@Project"].Value = projectName;
    
          SqlDataAdapter dap = new SqlDataAdapter(_cmd);
          dap.Fill(resultTable);
       }
    
       return resultTable;
    }
    

    Of course:

    • you might want to select based on other criteria (that would show up in your WHERE clause)
    • maybe you want to use a SqlDataReader and read that data into domain objects (instead of a DataTable)

    but the basic setup – have a specific method, pass in criteria, read the data with SqlConnection and SqlCommand in using blocks – will remain the same.

    Once you have the DataTable, you can bind it to an ASP.NET gridview:

    DataTable projectData = GetDataForProject("MyProject");
    
    gridView1.DataSource = projectData;
    gridView1.DataBind();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to submit a zend form but with lowercase values. Whatever user use
I want user to wait for specified time(4seconds) to get connected to server. If
i want to translate user entered english content to hindi language.So, for that whenever
i want to format number entered by user in dutch format. ie. use decimal
I want to check the strength of the password entered by user during registration.
I want to check password strength of password entered by user in Asp.Net page.
I'm using JQuery to get values from a form. When I submit the form
I want user to type some text in JTextField and it must match some
I had image for Products and i want user when click on image appear
I am working on a logic where I want user to be redirected to

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.