Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 10-Nov-12 15:51pm
sariqkhan1.4K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

try this code for binding to database and insert into it:
 
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();
            }
  Permalink  
Comments
Ritwesh at 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 at 11-Nov-12 4:31am
   
ok.you are right .
but he can use gridview for this case.
sariqkhan at 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 at 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 at 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?
sariqkhan at 11-Nov-12 4:33am
   
your Field Name that you want to insert from Textbox???
what i have to type here??
textbox1.text??
mohammad ehsan at 12-Nov-12 5:34am
   
you should look at your database's table ,inside your table there is field that you have created and has to be filled,and this is the FieldName you have to retype it instead of the sentence you commented. for example you have a table by the name of Person ,there will be a field by the name of Name.you should put Name as a value instead of commented sentece.
sariqkhan at 13-Nov-12 1:08am
   
oh you mean the column of the database. sorry i misunderstood
sariqkhan at 13-Nov-12 9:38am
   
private void button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\project\Projects\labelnameinsecondformtry\labelnameinsecondformtry\Database1.mdf;Integrated Security=True;User Instance=True";
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
conn.Open();
try
{
cmd.CommandText = "Insert into Table2 values(username)";
cmd.Parameters.Add("@username", SqlDbType.VarChar).Value = textBox1.Text;
cmd.ExecuteNonQuery();
}
finally
{
conn.Close();
MessageBox.Show("hello welcome");
}
}
it is showing invalid column name username???
and i have a database with column name username
what i have to do?

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

  Print Answers RSS
0 OriginalGriff 349
1 Sergey Alexandrovich Kryukov 319
2 Maciej Los 260
3 George Jonsson 185
4 King_Fisher 160
0 Sergey Alexandrovich Kryukov 10,934
1 Maciej Los 5,614
2 OriginalGriff 5,603
3 CPallini 3,879
4 BillWoodruff 3,579


Advertise | Privacy | Mobile
Web01 | 2.8.141030.1 | Last Updated 11 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100