473,408 Members | 2,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How to add and edit data in the textbox with binding

I created a form with a switchboard where the user click on one of the buttons. When the form load i want the user to be able to add and edit data by clicking the appropriate button. When I click add, I'm unable to add data. Same with edit. I'm not sure if I'm using the binding correctly.

Expand|Select|Wrap|Line Numbers
  1. Public Class CustomerForm
  2.     Private theBinding As BindingSource
  3.     Private objCustomer As CustomerTier
  4.  
  5.     Private Sub CustomerForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6.         Dim dsCustomer As CustDataSet
  7.         objCustomer = New CustomerTier
  8.  
  9.         dsCustomer = objCustomer.getDataSet()
  10.  
  11.         Try
  12.             theBinding = New BindingSource()
  13.             theBinding.DataSource = dsCustomer
  14.             theBinding.DataMember = "Customer"
  15.  
  16.         Catch ex As Exception
  17.             MessageBox.Show("Error With the Binding", ex.Message)
  18.         End Try
  19.  
  20.         txtFirstName.DataBindings.Add("Text", theBinding, "First Name")
  21.         txtLastName.DataBindings.Add("Text", theBinding, "Last Name")
  22.         txtAddress.DataBindings.Add("Text", theBinding, "Address")
  23.         txtCity.DataBindings.Add("Text", theBinding, "City")
  24.         txtState.DataBindings.Add("Text", theBinding, "State")
  25.         txtZip.DataBindings.Add("Text", theBinding, "Zip Code")
  26.         lblID.DataBindings.Add("Text", theBinding, "Account Number")
  27.  
  28.         EnableNav()
  29.     End Sub
  30.  
  31.     Private Sub EnableEdit()
  32.         txtFirstName.ReadOnly() = True
  33.         txtLastName.ReadOnly() = True
  34.         txtAddress.ReadOnly() = True
  35.         txtCity.ReadOnly() = True
  36.         txtState.ReadOnly() = True
  37.         txtZip.ReadOnly() = True
  38.  
  39.         btnCancel.Enabled = True
  40.         btnFirst.Enabled = False
  41.         btnPrev.Enabled = False
  42.         btnNext.Enabled = False
  43.         btnLast.Enabled = False
  44.     End Sub
  45.  
  46.     Private Sub EnableNav()
  47.         txtFirstName.ReadOnly() = True
  48.         txtLastName.ReadOnly() = True
  49.         txtAddress.ReadOnly() = True
  50.         txtCity.ReadOnly() = True
  51.         txtState.ReadOnly() = True
  52.         txtZip.ReadOnly() = True
  53.  
  54.         btnCancel.Enabled = False
  55.         btnFirst.Enabled = True
  56.         btnPrev.Enabled = True
  57.         btnNext.Enabled = True
  58.         btnLast.Enabled = True
  59.     End Sub
  60.  
  61.     Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
  62.         If btnAdd.Text = "Add" Then
  63.             btnAdd.Text = "Save"
  64.             EnableEdit()
  65.             btnEdit.Enabled = False
  66.             'btnDelete.Enabled = False
  67.  
  68.             theBinding.AddNew()
  69.  
  70.         Else
  71.             btnAdd.Text = "Add"
  72.             EnableNav()
  73.             btnEdit.Enabled = True
  74.             'btnDelete.Enabled = True
  75.             theBinding.EndEdit()
  76.             objCustomer.setDataSet()
  77.         End If
  78.     End Sub
  79.  
  80.     Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
  81.         If btnEdit.Text = "Edit" Then
  82.             btnEdit.Text = "Save"
  83.             EnableEdit()
  84.             btnAdd.Enabled = False
  85.             'btnDelete.Enabled = False
  86.  
  87.         Else
  88.             btnEdit.Text = "Edit"
  89.             EnableNav()
  90.             btnAdd.Enabled = True
  91.             'btnDelete.Enabled = True
  92.             theBinding.EndEdit()
  93.             objCustomer.setDataSet()
  94.         End If
  95.     End Sub
  96.  
Nov 3 '10 #1
0 1495

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Apple | last post by:
I had create a query with one table and one query, and then create form with that query using wizard, but I can't append or edit data in that form & query. Please help!
0
by: Alex | last post by:
I found some good information On "Use the DataList Control to Present and Edit Data" at this site http://www.dedicatedsolutions.co.uk/DesktopDefault.aspx?tabid=62 It is worth the click
0
by: Alex | last post by:
Imports System Imports System.Data Imports System.Data.SqlClient Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Configuration Public Class Main : Inherits Page ...
6
by: shariffshiraz | last post by:
I am using a FormView, Insert Template. I have 3 textboxes which are bound. I would like to use a default (static) value in one of the textboxes. Here's the (relevant) sample code: ...
4
by: T.Jackson | last post by:
Hi guys, I want to display the data of a table in a datagrid in one form, & enable the user to edit the details of a particular record in another form. I want the following features, 1....
0
by: Sam | last post by:
I am trying to use a Simple form with 3 fields from SQL NorthWind Database (Order Details Table with 3 Fields. - OrderId, ProductId and Unit Price). The Field Unit Price has a data type of 'Money...
0
by: Sam | last post by:
Folks.. I am trying to use a Simple form with 3 fields from SQL NorthWind Database (Order Details Table with 3 Fields. - OrderId, ProductId and Unit Price). The Field Unit Price has a data...
1
by: ortega.rad | last post by:
I have a form which allows you to select a record. That record has other records asscociated with it via a table. The asscociated records of the record selected on the main form are shown in a...
1
by: lchomany | last post by:
Good Day! I have a macro created to Open my subform and is embedded in the Command Button. Main Form: frmADD NEW ENTITY NAME Subform: frmEntityAwards My macro filters to the specific...
3
by: lisles | last post by:
i need to edit data from the databse through a form.my code is below <?php require_once "../inc/functions.php"; require_once "../inc/vars.inc.php"; sessionCheck(); session_start(); ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.