Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Date capture form in C#, Need assistance
Message
From
12/03/2014 05:14:40
 
 
To
All
General information
Forum:
ASP.NET
Category:
Forms
Title:
Date capture form in C#, Need assistance
Environment versions
Environment:
C# 4.0
OS:
Windows 8
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01596206
Message ID:
01596206
Views:
49
Hi Guys,

I am busy teaching myself C#. I have gone the through all the console applications learning syntax and now I want to do a data entry form.
This is what I have done so far. I have a form that has a datagridview on it with textboxes for each item in the grid. I want to have an add,edit,delete and canel button. I have the grid and the text boxes bound to a SQL database table and loaded as follows:
command = new SqlCommand();
 adapter = new SqlDataAdapter();
 dataset = new DataSet();
 bindingSource = new BindingSource();
 command.Connection = connection;
 command.CommandText = "SELECT * FROM customer";
 adapter.SelectCommand = command;
try
 {
 adapter.Fill(dataset, "customer");
 bindingSource.DataSource = dataset;
 bindingSource.DataMember = "customer";
 dgvCustomers.DataSource = bindingSource;
 txtCustNo.DataBindings.Add("Text", bindingSource.DataSource, "Customer.CustNo");
 txtName.DataBindings.Add("Text", bindingSource.DataSource, "Customer.CustName");
 txtEmail.DataBindings.Add("Text", bindingSource.DataSource, "Customer.email");
 txtTelNo.DataBindings.Add("Text", bindingSource.DataSource, "Customer.TelNo");
 cboGender.DataBindings.Add("Text", bindingSource.DataSource, "Customer.Gender");
 cboTerms.DataBindings.Add("Text", bindingSource.DataSource, "Customer.PaymentTerm");

 }
catch (SqlException)
 {
MessageBox.Show("Error occured while connecting to database.");
Application.Exit();
 }
The data loads into the grid correctly. To get the textboxes to refresh when the row in the colum changes I use currency manager:
CurrencyManager cm = (CurrencyManager)this.BindingContext[dataset, "Customer"];
long rowPosition = (long)cm.Position;
 cm.Position = dgvCustomers.CurrentRow.Index; 
From what I have read using the currency manager like I have is an old method and I should use the internal currency manager of the bindingsouce. But I have not been able work out how.

My questions are:
1) How would you use the internal currency manager of the datasource?
2) When I click on add I clear the textboxes so I can enter data. If then decided to cancel and not save, how do I refesh the textboxes? As at this point the data in the grid changes to?
3) Am I using the correct best practice method?
4) Is there perhaps an example I can refer to that shows you basic data entry forms that I can learn from and design my own?

Thanks in advance guys.
Stuart Reid

True nobility lies not in being superior to another man, but in being superior to one’s previous self
Reply
Map
View

Click here to load this message in the networking platform