Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
i am using databinding property of textbox control.
it is showing only one name from the column. does this propoerty is used for such work?
can you explain databinding property of textbox in C#, i have searched but no answer was found. can anyone helpme out to explore the databinding property
Posted

A text box only shows one value - so all it can ever show is a single value from a single column of your data source.

If you want to show multiple rows, or multiple columns, or both, then you need to use a multiple row control, such as a DataGridView
 
Share this answer
 
Hi
It is not possible to represent your entire database column in one text box line. I always prefer unbound database connectivity as it provides greater flexibility and reduce load on the server computer. Still, if you insist upon using the bound control then I would suggest you to go for BindingNavigator or DataGridView. Explore the possibilities of using BindingNavigator it is quite interesting if you are new to database handling.

Bound controls provide you a control in the user interface which is directly connected to your database. As a result of this whenever you make any change to value of the controls(say, you change the Name of a person in a DataGridView control) the change is reflected in the main database itself. To make these changes happen you need not write any extra code. While unbound controls establishes connection to the database only when needed. So any change made at the front end does not reflect in the database. You need to write down separate code for that. The facility of unbound control is that your are not constantly connected to your database which reduces the pressure on the server. Further you can interact with the database any way you want every time.

Though bound controls are easier and quicker to create, unbound controls serve better.


Ritwesh.
 
Share this answer
 
try this code for binding to database and insert into it:

C#
SqlConnection conn = new SqlConnection();
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["Your ConnectionString name"].ConnectionString;
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            conn.Open();
            try
            {
                cmd.CommandText = "Insert into [Database Name] values([your Field Name that you want to insert from Textbox])";
                cmd.Parameters.Add("@Your FieldName", SqlDbType.VarChar).Value = textbox1.Text;
                cmd.ExecuteNonQuery();
            }
            catch (SqlException se)
            {
               Page.Title = "Exception :" + ex.Message;
            }
            finally
            {
                    conn.Close();
            }
 
Share this answer
 
Comments
Ritwesh 11-Nov-12 3:14am    
What I see is that you are using an unbound database connection and you are trying to enter a value into your database according to some parameters but the question lies whether one can use the databinding property for more than one line. This is not possible because text box represents a single line.
mohammad ehsan 11-Nov-12 4:31am    
ok.you are right .
but he can use gridview for this case.
sariqkhan 11-Nov-12 4:36am    
bro i thot i can use textbox with autocomplete mode with binding property so that i can type the first letter can i can get the values from the database column but it is not possible
Ritwesh 12-Nov-12 11:45am    
As I can see from your comment is that you want to create a mode in which you can type 'autocomplete mode with binding property so that i can type the first letter can i can get the values from the database column'. Okay this can be done but not with textbox. You need to do this with a ComboBox. I would suggest you to create an unbound connection to your database to get all the data in a particular code. Then you can add each data value of the specific column to your ComboBox's AutoCompleteCustomSource. Then set the AutoCompleteSource to CustomSource. This shall do your bit. If you want I can supply you with that code too.
sariqkhan 13-Nov-12 1:08am    
yup can i you give? i will use that one
and i can bound the connection with combo box which is provided by propoerty of combobox. so i dont have to write the code for that?
right?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900