CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2012
    Posts
    5

    Populate value in textboxes

    hi guys,
    I have budget table in my sql database and there are some field like budgetYear,Long-term,short-term etc.. and I have textboxes and i want to get value from textbox. so how can i get? can you guys please help me.


    Thanks a lot

  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: Populate value in textboxes

    So you have a sql db and a form and would like to bind some controls to some fields.

    Have you at least decided how your software will deal with db?
    are you going for Entity Framework?
    are you going for Linq to Sql?
    are you going for a custom Dal with Objects to map your tables?
    are you going for strongly typed DataSet?
    are you going for simple DataTables?
    ?
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

  3. #3
    Join Date
    May 2007
    Location
    Denmark
    Posts
    623

    Re: Populate value in textboxes

    That was hardly a useful reply, as the OP will obviously not be able to answer those questions.

    I would suggest looking at the SqlDataReader class.

    This sample should get you started (modified from MSDN)
    Code:
    private static void ReadOrderData(string connectionString)
    {
        string queryString = "SELECT whatever FROM some_table";
    
        using (SqlConnection connection = new SqlConnection(connectionString))
        {
            using SqlCommand command = new SqlCommand(queryString, connection))
            {
                command.Connection.Open();
    
                using(SqlDataReader reader = command.ExecuteReader())
                {
    
                    // Call Read before accessing data.
                    while (reader.Read())
                    {
                        textBox1.Text = reader["column_name"].ToString();
                    }
    
                }
            }
        }
    }
    EDIT: I might have misunderstood, and you want to save the textbox values to your database? If that's the case, let me know and I'll help out as best I can
    It's not a bug, it's a feature!

  4. #4
    Join Date
    Mar 2012
    Posts
    5

    Re: Populate value in textboxes

    hi guys,
    I have textboxes and I want to display a last row from database table.
    I also have add button ,it will insert data in databse table.
    So when user update table every time I want to display last row only.

    what should I do?


    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured