Click here to Skip to main content
15,894,410 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I'm struggling to understand the concept of databinding, but it may be because i'm confusing myself. I cant work out if databinding is any more than what I've already done. Below is a snippet of my code connecting to my SQL database. Is this databinding? Can anyone help please explain before I spend several more days reading up on it.

Thanks

try
           {
               string UserIDSort = tbxUserID.Text.Remove(2, 6);
               int UserIDInt = Convert.ToInt32(UserIDSort);
               if (UserIDInt == 10 || UserIDInt == 15 || UserIDInt == 20)
               {
               SqlConnection connection = new SqlConnection("Data Source=OMEGA; Initial Catalog = Military; Integrated Security = True; Pooling = False");
               connection.Open();
               string s2 = "SELECT UserID, Password FROM [dbo].[Logon];";
               SqlDataAdapter adapter = new SqlDataAdapter(s2, connection);
               SqlCommandBuilder cmdBuilder = new SqlCommandBuilder(adapter);
               DataSet dataset = new DataSet();
               adapter.Fill(dataset);
               DataRow r = dataset.Tables[0].NewRow();
               string un = (tbxUserID.Text);
               string up = (tbxPassword.Text);
               r["UserID"] = un;
               r["Password"] = up;

               dataset.Tables[0].Rows.Add(r);
               adapter.Update(dataset);
               dataset.AcceptChanges();
               }
               else
               {
                   MessageBox.Show("Username Must Start with 10, 15 or 20 and must be 8 characters long");
               }
           }
Posted
Updated 18-May-11 6:31am
v3

1 solution

"Data binding is the process that establishes a connection between the application UI and business logic."

http://msdn.microsoft.com/en-us/library/ms752347(v=VS.90).aspx[^]

In your snippet you have neither business logic nor a UI, ergo, this is not databinding.

This would be an example of databinding
DropDownList ddl = new DropDownList();
ddl.DataSource = myDatasource;
ddl.DataBind();
 
Share this answer
 
Comments
WurmInfinity 18-May-11 12:41pm    
hmm ok so its got to be read in from the database? so essentially read in and put into the drop down.
mario_silent 18-May-11 12:51pm    
Connecting to your database and retrieving data is part of the business logic, data binding as mentioned above is when you use the data you retrieved in some sort of UI element, it doesn't have to be a dropdown, it can be any control that can hold your data and depends on your app, for winforms you can use DataGridView, a ComboBox, etc. the DropdownList is for web just as the GridView which is similar to the DataGridView.
SO the binding occurs when you assing a DataSource to the Control, which can bea DataSet, DataTable, List, amongst others.
WurmInfinity 18-May-11 13:02pm    
Ahh ok thats easy enough, I think I was just over complicating it. Thanks a lot :)

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