473,722 Members | 2,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

update oledb database from text field

I need the code to update the database when Save is clicked and a text field
has changed. This should be very easy since I used Microsoft's wizards for
the OleDBAdapter and OleDBConnection , and DataSet; and all I'm doing is
showing one record in text fields, allowing the user to modify the text
fields, and then updating the database again when the user clicks the Save
button. The fields already show the correct data record since I have the
DataBinding text property filled in for the text fields. I need the code to
put in the save button click event.

Here are SOME of the portions I already have, most of it from the wizards...
....
using System.Data;
using System.Data.Ole Db;
....
namespace EsperanzaThread s
public class frmComapnyEdit : System.Windows. Forms.Form
....
private System.Windows. Forms.TextBox txtCompany;
private System.Windows. Forms.TextBox txtCompanyID;
private System.Data.Ole Db.OleDBCommand oleDbUpdateComm and1;
private EsperanzaThread s.dsCompanyEdit dsCompanyEdit1;
private string strCommandText;
private string strCurrent;
....
public frmComanyEdit(s tring idname)
{strCurrent = idname;
InitializeCompo nent();
....
private void InitializeCompo nent()
{
this.txtCompany = new System.Windows. Forms.TextBox() ;
this.txtCompany ID = new System.Windows. Forms.TextBox() ;
this.lblActive = new System.Windows. Forms.Label();
this.lblCompany = new System.Windows. Forms.Label();
this.lblCompany ID = new System.Windows. Forms.Label();
this.oleDbDataA dapterCompanyEd it = new System.Data.Ole Db.OleDbDataAda pter();
this.oleDbUpdat eCommand1 = new System.Data.Ole Db.OleDbCommand ();
this.oleDbConne ction1 = new System.Data.Ole Db.OleDbConnect ion();
this.dsCompanyE dit1 = new EsperanzaThread s.dsCompanyEdit ();
....
this.txtCompany ID.DataBindings .Add(new System.Windows. Forms.Binding(" Text",
this.dsCompanyE dit1, "tblCompany.Com panyId"));
this.oleDbDataA dapterCompanyEd it.TableMapping s.AddRange(new
System.Data.Com mon.DataTableMa pping[] {
new System.Data.Com mon.DataTableMa pping("Table", "tblCompany ", new
System.Data.Com mon.DataColumnM apping[] {
new System.Data.Com mon.DataColumnM apping("Company Id", "CompanyId" ),
new System.Data.Com mon.DataColumnM apping("Company ", "Company")} )});
this.oleDbDataA dapterCompanyEd it.UpdateComman d = this.oleDbUpdat eCommand1;

this.oleDbUpdat eCommand1.Comma ndText = "UPDATE tblCompany SET CompanyId = ?,
Company = ?, Active = ? WHERE (CompanyId = ?" +") AND (Active = ?) AND
(Company = ?)";
this.oleDbUpdat eCommand1.Conne ction = this.oleDbConne ction1;
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("CompanyId" ,
System.Data.Ole Db.OleDbType.Va rWChar, 1, "CompanyId" ));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Company",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Company")) ;
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Active",
System.Data.Ole Db.OleDbType.Bo olean, 2, "Active"));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Co mpanyId",
System.Data.Ole Db.OleDbType.Va rWChar, 1,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "CompanyId" , System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Ac tive",
System.Data.Ole Db.OleDbType.Bo olean, 2, System.Data.Par ameterDirection .Input,
false, ((System.Byte)( 0)), ((System.Byte)( 0)), "Active",
System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Co mpany",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "Company", System.Data.Dat aRowVersion.Ori ginal, null));
....
this.dsCompanyE dit1.DataSetNam e = "dsCompanyEdit" ;
....
private void frmCompanyEdit_ Load(object sender, System.EventArg s e)
{
strCommandText = "SELECT CompanyID, Company, Active FROM tblCompany WHERE
CompanyID = '" + strCurrent + "'";
this.oleDbSelec tCommand1.Comma ndText = strCommandText;
oleDbDataAdapte rCompanyEdit.Fi ll(dsCompanyEdi t1);
}

private void btnSave_Click(o bject sender, System.EventArg s e) {
// WHAT SHOULD GO IN HERE?

The following is what I had in the btnSave_Click when I wanted to add a new
record, but I think there is probably an even easier way using more of
Microsoft's prewritten code and I don't know how to do it. But what I really
care about is figuring out how to update the database when a record is
modified. I played with this code and can't figure out how to convert it to
do updates.

//Code I used for adding a new record:
DataTable dt = dsCompanyAdd1.T ables["tblCompany "];
DataRow dr = dt.NewRow();
drNew["CompanyID"] = this.txtCompany ID.Text;
drNew["Company"] = this.txtCompany .Text;
drNew["Active"] = this.cmbActive. Text;
dt.Rows.Add(drN ew);
oleDbDataAdapte rCompanyAdd.Upd ate(dsCompanyAd d1,"tblCompany" );
dsCompanyAdd1.C lear();
oleDbDataAdapte rCompanyAdd.Fil l(dsCompanyAdd1 );
this.Close();

I found knowlegebase and help articles but I am confused since the
parameters, UpdateCommand, data adapter, and data connection are already
written by Microsoft's wizard and I couldn't find any articles that showed me
how to use the prewritten code.

The following code is the best example I could find on how to do what I
want, but I still can't figure out which portions I need, given the Microsoft
prewritten Wizard code. Could you show me the correct portions to use with
the prewritten wizard code, or better yet, what the code should exactly be
for the Save_Click event?

Sample from knowledgebase:
custDA.UpdateCo mmand.Parameter s.Add("@Custome rID", OleDbType.Char, 5,
"CustomerID ");

custDA.UpdateCo mmand.Parameter s.Add("@Company Name", OleDbType.VarCh ar, 40,
"CompanyNam e");

OleDbParameter myParm =
custDA.UpdateCo mmand.Parameter s.Add("@OldCust omerID", OleDbType.Char, 5,
"CustomerID ");
myParm.SourceVe rsion = DataRowVersion. Original;

public static OleDbDataAdapte r CreateCustomerA dapter(OleDbCon nection conn)
{
OleDbDataAdapte r da = new OleDbDataAdapte r();
OleDbCommand cmd;
OleDbParameter parm;

// Create the UpdateCommand.

cmd = new OleDbCommand("U PDATE Customers SET CustomerID = @CustomerID,
CompanyName = @CompanyName " +
"WHERE CustomerID = @oldCustomerID" , conn);

cmd.Parameters. Add("@CustomerI D", OleDbType.Char, 5, "CustomerID ");
cmd.Parameters. Add("@CompanyNa me", OleDbType.VarCh ar, 40, "CompanyNam e");

parm = cmd.Parameters. Add("@oldCustom erID", OleDbType.Char, 5,
"CustomerID ");
parm.SourceVers ion = DataRowVersion. Original;

da.UpdateComman d = cmd;

return da;
}

Thanks,
Pam
Nov 16 '05 #1
9 4775
Hi Pam,

Thank you for your posting. Regarding on the issue, I am
finding proper resource to assist you and we will update as soon as posible.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security(This posting is provided "AS IS",
with no warranties, and confers no rights.)

Nov 16 '05 #2
Hi Pam,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know the best way to put
the new data to the database using DataAdapter. If there is any
misunderstandin g, please feel free to let me know.

Based on the code you have provided, I think your code is fine. The only
thing that we could improve, is to add data binding to the form, which
makes the newly added row goes to the DataTable directly. And data in each
TextBox will be filled to the newly added row automatically. Here is an
article about data binding in windows forms.

http://msdn.microsoft.com/library/de...us/dndotnet/ht
ml/databindingadon et.asp

Since you're using the DataAdapter wizard to generate the DataAdapter and
DataSet, we needn't add the parameters to the OleDbCommand ourselves.
Everything has been done by the wizard. It has generated code for you. If
you expand the region of Windows Form Designer generated code, you will see
the OleDbCommand with parameters created.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #3
No, that is not what I need. As I indicated in my post, what I really need
is the UPDATE code, not add code. As I indicated in my initial post, I have
the add capabilities working, and it is nice to know how to improve it, but
what I really need is the update code, to work with the code that the Wizards
wrote, for the save button.

As I indicated in my initial post, I do have the Data Binding text fields
already set properly and it is working properly for my add form.

Second, as far as I can tell, the reference you gave me only shows how to
bind to text fields to DISPLAY the fields. It does not say how to add,
update, or delete data in text fields.

PLEASE, I really need you to help me with this since it is the last step in
handing the finished project over to my client. I've been waiting since
Sunday to finish the project, all based on getting the Save button on the
Update form to work.

Thanks,
Pam
"Kevin Yu [MSFT]" wrote:
Hi Pam,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know the best way to put
the new data to the database using DataAdapter. If there is any
misunderstandin g, please feel free to let me know.

Based on the code you have provided, I think your code is fine. The only
thing that we could improve, is to add data binding to the form, which
makes the newly added row goes to the DataTable directly. And data in each
TextBox will be filled to the newly added row automatically. Here is an
article about data binding in windows forms.

http://msdn.microsoft.com/library/de...us/dndotnet/ht
ml/databindingadon et.asp

Since you're using the DataAdapter wizard to generate the DataAdapter and
DataSet, we needn't add the parameters to the OleDbCommand ourselves.
Everything has been done by the wizard. It has generated code for you. If
you expand the region of Windows Form Designer generated code, you will see
the OleDbCommand with parameters created.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #4
Hi Pam,

Sorry for the misunderstandin g. Since there are many ways which enable us
to update data from the DataSet to the database, I would like to confirm
more information on how data was binded to the form controls.

Is the data binding accomplished by setting the DataBinding options in the
Form Designer? It make data displayed in those TextBoxes as soon as data
are filled to the DataSet.

If the above is true, it will be very simple for us to update the database.
First we need to get a CurrencyManager from the binding context and call
its EndCurrentEdit method to save the current edit data in the DataSet. To
get the CurrencyManager object, please check the following link:

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfsystemwind owsformscurrenc ymanagerclassto pic.asp

Then, we simply call
oleDbDataAdapte rCompanyAdd.Upd ate(dsCompanyAd d1,"tblCompany" ); This makes
full use of the designer generated Update command and update alll the
inserted, modified and deleted rows.

If the above question is not true, we have to do the following for updating:
1. Search in the DataTable and get the reference to the row currently we
are modifying.
2. Assign all value in the rows with new data like the following.

drModified["CompanyID"] = this.txtCompany ID.Text;
drModified["Company"] = this.txtCompany .Text;
drModified["Active"] = this.cmbActive. Text;

3. Call oleDbDataAdapte rCompanyAdd.Upd ate(dsCompanyAd d1,"tblCompany" ); to
update the rows which have been changed to the database.

However, for more advice on this, I have to get more detailed information
on the architecture of your app.

Here are some information on DataBinding and some good practices on windows
form data architectures.

http://msdn.microsoft.com/library/de...us/vbcon/html/
vboriWindowsFor msDataArchitect ure.asp

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #5
We are very close. The following code executes without errors, but actually
does not update the database. I think my currency statement is either wrong
or in the wrong place?... it's in the form_load event. If that's not the
problem, then what did I do wrong? Look at the btnSave_Click and the form
load event, the rest of my code should be correct.

Databindings for the fields, in the Text property:
for txtCompanyid the value is dsCompanyEdit1 - tblCompany.Comp anyId
for txtCompany the value is dsCompanyEdit1 - tblCompany.Comp any
for cmbActive the value is dsCompanyEdit1 - tblCompany.Acti ve

for the Item Collection property of cmbActive I have the values True and
False, which are the only allowed values for this field.

using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Data.Ole Db;

namespace EsperanzaThread s
{
/// <summary>
/// Summary description for frmCompanyEdit.
/// </summary>
public class frmCompanyEdit : System.Windows. Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;
private string strCommandText;
private System.Windows. Forms.ComboBox cmbActive;
private System.Windows. Forms.Button btnCancel;
private System.Windows. Forms.Button btnSave;
private System.Windows. Forms.TextBox txtCompany;
private System.Windows. Forms.TextBox txtCompanyID;
private System.Windows. Forms.Label lblActive;
private System.Windows. Forms.Label lblCompany;
private System.Windows. Forms.Label lblCompanyID;
private System.Data.Ole Db.OleDbDataAda pter oleDbDataAdapte rCompanyEdit;
private System.Data.Ole Db.OleDbCommand oleDbSelectComm and1;
private System.Data.Ole Db.OleDbCommand oleDbInsertComm and1;
private System.Data.Ole Db.OleDbCommand oleDbUpdateComm and1;
private System.Data.Ole Db.OleDbCommand oleDbDeleteComm and1;
private System.Data.Ole Db.OleDbConnect ion oleDbConnection 1;
private EsperanzaThread s.dsCompanyEdit dsCompanyEdit1;
private string strCurrent;

public frmCompanyEdit( )
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

//
// TODO: Add any constructor code after InitializeCompo nent call
//
}

public frmCompanyEdit( string idname)
{
//
// Required for Windows Form Designer support
//
strCurrent = idname;
InitializeCompo nent();
this.Text = "Edit Company";
//
// TODO: Add any constructor code after InitializeCompo nent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.cmbActive = new System.Windows. Forms.ComboBox( );
this.dsCompanyE dit1 = new EsperanzaThread s.dsCompanyEdit ();
this.btnCancel = new System.Windows. Forms.Button();
this.btnSave = new System.Windows. Forms.Button();
this.txtCompany = new System.Windows. Forms.TextBox() ;
this.txtCompany ID = new System.Windows. Forms.TextBox() ;
this.lblActive = new System.Windows. Forms.Label();
this.lblCompany = new System.Windows. Forms.Label();
this.lblCompany ID = new System.Windows. Forms.Label();
this.oleDbDataA dapterCompanyEd it = new System.Data.Ole Db.OleDbDataAda pter();
this.oleDbDelet eCommand1 = new System.Data.Ole Db.OleDbCommand ();
this.oleDbConne ction1 = new System.Data.Ole Db.OleDbConnect ion();
this.oleDbInser tCommand1 = new System.Data.Ole Db.OleDbCommand ();
this.oleDbSelec tCommand1 = new System.Data.Ole Db.OleDbCommand ();
this.oleDbUpdat eCommand1 = new System.Data.Ole Db.OleDbCommand ()
((System.Compon entModel.ISuppo rtInitialize)(t his.dsCompanyEd it1)).BeginInit ();
this.SuspendLay out();
//
// cmbActive
//
this.cmbActive. DataSource = this.dsCompanyE dit1.tblCompany ;
this.cmbActive. DisplayMember = "Active";
this.cmbActive. DropDownStyle =
System.Windows. Forms.ComboBoxS tyle.DropDownLi st;
this.cmbActive. Location = new System.Drawing. Point(80, 56);
this.cmbActive. MaxDropDownItem s = 2;
this.cmbActive. Name = "cmbActive" ;
this.cmbActive. Size = new System.Drawing. Size(88, 21);
this.cmbActive. TabIndex = 16;
//
// dsCompanyEdit1
//
this.dsCompanyE dit1.DataSetNam e = "dsCompanyEdit" ;
this.dsCompanyE dit1.Locale = new System.Globaliz ation.CultureIn fo("en-US");
//
// btnCancel
//
this.btnCancel. DialogResult = System.Windows. Forms.DialogRes ult.Cancel;
this.btnCancel. Location = new System.Drawing. Point(280, 88);
this.btnCancel. Name = "btnCancel" ;
this.btnCancel. TabIndex = 18;
this.btnCancel. Text = "Cancel";
this.btnCancel. Click += new System.EventHan dler(this.btnCa ncel_Click);
//
// btnSave
//
this.btnSave.Lo cation = new System.Drawing. Point(184, 88);
this.btnSave.Na me = "btnSave";
this.btnSave.Ta bIndex = 17;
this.btnSave.Te xt = "Save";
this.btnSave.Cl ick += new System.EventHan dler(this.btnSa ve_Click);
//
// txtCompany
//
this.txtCompany .DataBindings.A dd(new System.Windows. Forms.Binding(" Text",
this.dsCompanyE dit1, "tblCompany.Com pany"));
this.txtCompany .Location = new System.Drawing. Point(80, 32);
this.txtCompany .Name = "txtCompany ";
this.txtCompany .Size = new System.Drawing. Size(272, 20);
this.txtCompany .TabIndex = 15;
this.txtCompany .Text = "";
//
// txtCompanyID
//
this.txtCompany ID.DataBindings .Add(new System.Windows. Forms.Binding(" Text",
this.dsCompanyE dit1, "tblCompany.Com panyId"));
this.txtCompany ID.Location = new System.Drawing. Point(80, 8);
this.txtCompany ID.MaxLength = 1;
this.txtCompany ID.Name = "txtCompany ID";
this.txtCompany ID.Size = new System.Drawing. Size(24, 20);
this.txtCompany ID.TabIndex = 14;
this.txtCompany ID.Text = "";
//
// lblActive
//
this.lblActive. Location = new System.Drawing. Point(8, 56);
this.lblActive. Name = "lblActive" ;
this.lblActive. Size = new System.Drawing. Size(72, 23);
this.lblActive. TabIndex = 21;
this.lblActive. Text = "Active";
//
// lblCompany
//
this.lblCompany .Location = new System.Drawing. Point(8, 32);
this.lblCompany .Name = "lblCompany ";
this.lblCompany .Size = new System.Drawing. Size(72, 23);
this.lblCompany .TabIndex = 20;
this.lblCompany .Text = "Company";
//
// lblCompanyID
//
this.lblCompany ID.Location = new System.Drawing. Point(8, 8);
this.lblCompany ID.Name = "lblCompany ID";
this.lblCompany ID.Size = new System.Drawing. Size(72, 23);
this.lblCompany ID.TabIndex = 19;
this.lblCompany ID.Text = "Company ID";
//
// oleDbDataAdapte rCompanyEdit
//
this.oleDbDataA dapterCompanyEd it.DeleteComman d = this.oleDbDelet eCommand1;
this.oleDbDataA dapterCompanyEd it.InsertComman d = this.oleDbInser tCommand1;
this.oleDbDataA dapterCompanyEd it.SelectComman d = this.oleDbSelec tCommand1;
this.oleDbDataA dapterCompanyEd it.TableMapping s.AddRange(new
System.Data.Com mon.DataTableMa pping[] {
new System.Data.Com mon.DataTableMa pping("Table", "tblCompany ", new
System.Data.Com mon.DataColumnM apping[] {
new System.Data.Com mon.DataColumnM apping("Company Id", "CompanyId" ),
new System.Data.Com mon.DataColumnM apping("Company ", "Company"),
new System.Data.Com mon.DataColumnM apping("Active" , "Active")}) });
this.oleDbDataA dapterCompanyEd it.UpdateComman d = this.oleDbUpdat eCommand1;
//
// oleDbDeleteComm and1
//
this.oleDbDelet eCommand1.Comma ndText = "DELETE FROM tblCompany WHERE
(CompanyId = ?) AND (Active = ?) AND (Company = ?)";
this.oleDbDelet eCommand1.Conne ction = this.oleDbConne ction1;
this.oleDbDelet eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Co mpanyId",
System.Data.Ole Db.OleDbType.Va rWChar, 1,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "CompanyId" , System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbDelet eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Ac tive",
System.Data.Ole Db.OleDbType.Bo olean, 2, System.Data.Par ameterDirection .Input,
false, ((System.Byte)( 0)), ((System.Byte)( 0)), "Active",
System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbDelet eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Co mpany",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "Company", System.Data.Dat aRowVersion.Ori ginal, null));
//
// oleDbConnection 1
//
this.oleDbConne ction1.Connecti onString = @"Jet OLEDB:Global Partial Bulk
Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data
Source=""<path omitted>EspThr. mdb"";Jet OLEDB:Engine
Type=5;Provider =""Microsoft.Je t.OLEDB.4.0"";J et OLEDB:System database=;Jet
OLEDB:SFP=False ;persist security info=False;Exte nded Properties=;Mod e=Share
Deny None;Jet OLEDB:Encrypt Database=False; Jet OLEDB:Create System
Database=False; Jet OLEDB:Don't Copy Locale on Compact=False;J et OLEDB:Compact
Without Replica Repair=False;Us er ID=<omitted>;Je t OLEDB:Global Bulk
Transactions=1" ;
//
// oleDbInsertComm and1
//
this.oleDbInser tCommand1.Comma ndText = "INSERT INTO tblCompany(Comp anyId,
Company, Active) VALUES (?, ?, ?)";
this.oleDbInser tCommand1.Conne ction = this.oleDbConne ction1;
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("CompanyId" ,
System.Data.Ole Db.OleDbType.Va rWChar, 1, "CompanyId" ));
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Company",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Company")) ;
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Active",
System.Data.Ole Db.OleDbType.Bo olean, 2, "Active"));
//
// oleDbSelectComm and1
//
this.oleDbSelec tCommand1.Comma ndText = "SELECT CompanyId, Company, Active
FROM tblCompany";
this.oleDbSelec tCommand1.Conne ction = this.oleDbConne ction1;
//
// oleDbUpdateComm and1
//
this.oleDbUpdat eCommand1.Comma ndText = "UPDATE tblCompany SET CompanyId =
?, Company = ?, Active = ? WHERE (CompanyId = ?" +
") AND (Active = ?) AND (Company = ?)";
this.oleDbUpdat eCommand1.Conne ction = this.oleDbConne ction1;
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("CompanyId" ,
System.Data.Ole Db.OleDbType.Va rWChar, 1, "CompanyId" ));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Company",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Company")) ;
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Active",
System.Data.Ole Db.OleDbType.Bo olean, 2, "Active"));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Co mpanyId",
System.Data.Ole Db.OleDbType.Va rWChar, 1,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "CompanyId" , System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Ac tive",
System.Data.Ole Db.OleDbType.Bo olean, 2, System.Data.Par ameterDirection .Input,
false, ((System.Byte)( 0)), ((System.Byte)( 0)), "Active",
System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Co mpany",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "Company", System.Data.Dat aRowVersion.Ori ginal, null));
//
// frmCompanyEdit
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(360, 118);
this.Controls.A dd(this.cmbActi ve);
this.Controls.A dd(this.btnCanc el);
this.Controls.A dd(this.btnSave );
this.Controls.A dd(this.txtComp any);
this.Controls.A dd(this.txtComp anyID);
this.Controls.A dd(this.lblActi ve);
this.Controls.A dd(this.lblComp any);
this.Controls.A dd(this.lblComp anyID);
this.Name = "frmCompanyEdit ";
this.Text = "frmCompanyEdit ";
this.Load += new System.EventHan dler(this.frmCo mpanyEdit_Load) ;
((System.Compon entModel.ISuppo rtInitialize)(t his.dsCompanyEd it1)).EndInit() ;
this.ResumeLayo ut(false);

}
#endregion

private void frmCompanyEdit_ Load(object sender, System.EventArg s e)
{
strCommandText = "SELECT CompanyID, Company, Active FROM tblCompany WHERE
CompanyID = '" + strCurrent + "'";
this.oleDbSelec tCommand1.Comma ndText = strCommandText;
oleDbDataAdapte rCompanyEdit.Fi ll(dsCompanyEdi t1);
CurrencyManager cm = (CurrencyManage r)this.BindingC ontext[dsCompanyEdit1,
"tblCompany "];
}

private void btnSave_Click(o bject sender, System.EventArg s e)
{
if ((this.txtCompa nyID.Text == "") || (this.txtCompan y.Text == "") ||
(this.cmbActive .Text == ""))
{
MessageBox.Show ("Informatio n may not be blank", "Problem Saving",
MessageBoxButto ns.OK, MessageBoxIcon. Exclamation,
MessageBoxDefau ltButton.Button 1);
this.txtCompany ID.Focus();
}
else
{
try
{
oleDbDataAdapte rCompanyEdit.Up date(dsCompanyE dit1,"tblCompan y");
MessageBox.Show ("Database Updated!");
dsCompanyEdit1. Clear();
oleDbDataAdapte rCompanyEdit.Fi ll(dsCompanyEdi t1);
this.Close();
}
catch(Exception ex)
{
MessageBox.Show (ex.Message, ex.GetType().To String());
this.txtCompany ID.Focus();
}
}

}

private void btnCancel_Click (object sender, System.EventArg s e)
{
this.Close();
}

}
}

Nov 16 '05 #6
Hi Pam,

Thanks for your code. As I mentioned in my last post, we have to get the
CurrencyManager from the binding context and call EndCurrentEdit method
before updating data to the database. This makes sure that the changes to
the DataSet has been saved. Here I made some changes to the Save method.

private void btnSave_Click(o bject sender, System.EventArg s e)
{
if ((this.txtCompa nyID.Text == "") || (this.txtCompan y.Text == "") ||
(this.cmbActive .Text == ""))
{
MessageBox.Show ("Informatio n may not be blank", "Problem Saving",
MessageBoxButto ns.OK, MessageBoxIcon. Exclamation,
MessageBoxDefau ltButton.Button 1);
this.txtCompany ID.Focus();
}
else
{
try
{
CurrencyManager cm =
(CurrencyManage r)this.BindingC ontext[dsCompanyEdit1, "tblCompany "];
cm.EndCurrentEd it(); //Get currencymanager and call EndCurrentEdit here
to make sure that changes have been saved to DataSet
oleDbDataAdapte rCompanyEdit.Up date(dsCompanyE dit1,"tblCompan y");
MessageBox.Show ("Database Updated!");
dsCompanyEdit1. Clear();
oleDbDataAdapte rCompanyEdit.Fi ll(dsCompanyEdi t1);
this.Close();
}
catch(Exception ex)
{
MessageBox.Show (ex.Message, ex.GetType().To String());
this.txtCompany ID.Focus();
}
}
}
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #7
Kevin,

Still almost there, but doing better than before...

Yes it now updates (mostly), amazing what cm.EndCurrentEd it(); will do!
Thank you!!!! (I read a lot about cm and tried using it earlier, but my code
didn't work since I never knew about EndCurrentEdit( ). Thanks.)

However, cmbActive, when I click on it and change it from True to False does
not update.

I am confused about the following properties:

Data Bindings
Selected Value
Selected Item
Tag
Text
and
Display Source
Display Member
and
Value Member
and
Items Collection...

I am never quite sure which I should use and why,
and notice that if I use Display Source/Display Member then I shouldn't use
DataBindings Text.
and also notice that if I use Items Collection then I shouldn't fill in
Display Source/Display Member.

What I want to do is limit cmbActive to only accept True/False so I used
Collection and put in True and False. I wanted it to update the database so
I used DataBindings Text property value of dsCompanyEdit1 -
tblCompany.Acti ve. It does allow me to choose only True/False, but it is not
updating Active in the database even though it is updating the text fields
properly (just not the combo box) and isn't giving me an error.

So first and most importantly I need to know what I did wrong and how to fix
it so I can finish the project.

And then second, I want to understand which of the above properties I use
for which controls and why. So maybe you could refer me to additional
articles? or explain a little more about what is happening? If this is too
much to ask or takes you a while, then just give me the immediate answer I
need to finish the project.

If you would take a little more of your extremely valuable time to help me
answer this last problem, then I will put up my final code in my next reply
so it will help others.

Thanks,
Pam
"Kevin Yu [MSFT]" wrote:
Hi Pam,

Thanks for your code. As I mentioned in my last post, we have to get the
CurrencyManager from the binding context and call EndCurrentEdit method
before updating data to the database. This makes sure that the changes to
the DataSet has been saved. Here I made some changes to the Save method.

private void btnSave_Click(o bject sender, System.EventArg s e)
{
if ((this.txtCompa nyID.Text == "") || (this.txtCompan y.Text == "") ||
(this.cmbActive .Text == ""))
{
MessageBox.Show ("Informatio n may not be blank", "Problem Saving",
MessageBoxButto ns.OK, MessageBoxIcon. Exclamation,
MessageBoxDefau ltButton.Button 1);
this.txtCompany ID.Focus();
}
else
{
try
{
CurrencyManager cm =
(CurrencyManage r)this.BindingC ontext[dsCompanyEdit1, "tblCompany "];
cm.EndCurrentEd it(); //Get currencymanager and call EndCurrentEdit here
to make sure that changes have been saved to DataSet
oleDbDataAdapte rCompanyEdit.Up date(dsCompanyE dit1,"tblCompan y");
MessageBox.Show ("Database Updated!");
dsCompanyEdit1. Clear();
oleDbDataAdapte rCompanyEdit.Fi ll(dsCompanyEdi t1);
this.Close();
}
catch(Exception ex)
{
MessageBox.Show (ex.Message, ex.GetType().To String());
this.txtCompany ID.Focus();
}
}
}
Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #8
Hi Pam,

When using DataBinding with a ComboBox, we need to do the following.

1. Set the ComboBox.DataSo urce to a certain DataTable.
2. Set the ComboBox.Displa yMember to one of the columns whose data will be
displayed in the dropdown list.
3. Set the ComboBox.ValueM ember to another column in the table whose data
represents the value of this row. Usually a primary key column.

Now, we have set the stuff in the dropdown list. And need to set which item
to display.

4. Bind the ComboBox.Select edValue property to the column that contains the
value of which item to display.

In the current case, there are only two fixed items, True and False in the
ComboBox dropdown list. I don't think we need the ComboBox to achieve this,
because it might be too complicated. I suggest we simply use a CheckBox. If
it is checked, it's true. Then it will be a simply binding. But make sure
to set a default value for the boolean column which the CheckBox binds to,
because of the following KB article.

http://support.microsoft.com/default...b;en-us;326440

Here are some more information and examples of Windows Form data binding.
HTH.

http://msdn.microsoft.com/library/de...us/cpqstart/ht
ml/cpsmpnetsamples-windowsformsdat abinding.asp

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #9
Thank you Kevin Yu!!! It totally works now.

I took out the combo box as you suggested and am now using a checkbox. I
did not use the DataBinding Text property but instead used the DataBindings
Checked property.

Here's the final code. Most of it was created using the oledb data adapter
wizard and dragging labels, text boxes, and a check boxes in to the form.

using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Data.Ole Db;

namespace EspThr
{
/// <summary>
/// Summary description for frmCompanyEdit.
/// </summary>
public class frmCompanyEdit : System.Windows. Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;
private string strCommandText;
private System.Windows. Forms.Button btnCancel;
private System.Windows. Forms.Button btnSave;
private System.Windows. Forms.TextBox txtCompany;
private System.Windows. Forms.TextBox txtCompanyID;
private System.Windows. Forms.Label lblActive;
private System.Windows. Forms.Label lblCompany;
private System.Windows. Forms.Label lblCompanyID;
private System.Data.Ole Db.OleDbDataAda pter oleDbDataAdapte rCompanyEdit;
private System.Data.Ole Db.OleDbCommand oleDbSelectComm and1;
private System.Data.Ole Db.OleDbCommand oleDbInsertComm and1;
private System.Data.Ole Db.OleDbCommand oleDbUpdateComm and1;
private System.Data.Ole Db.OleDbCommand oleDbDeleteComm and1;
private System.Data.Ole Db.OleDbConnect ion oleDbConnection 1;
private EspThr.dsCompan yEdit dsCompanyEdit1;
private System.Windows. Forms.CheckBox cbActive;
private string strCurrent;

public frmCompanyEdit( )
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

//
// TODO: Add any constructor code after InitializeCompo nent call
//
}

public frmCompanyEdit( string idname)
{
//
// Required for Windows Form Designer support
//
strCurrent = idname;
InitializeCompo nent();
this.Text = "Edit Company";
//
// TODO: Add any constructor code after InitializeCompo nent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.dsCompanyE dit1 = new EspThr.dsCompan yEdit();
this.btnCancel = new System.Windows. Forms.Button();
this.btnSave = new System.Windows. Forms.Button();
this.txtCompany = new System.Windows. Forms.TextBox() ;
this.txtCompany ID = new System.Windows. Forms.TextBox() ;
this.lblActive = new System.Windows. Forms.Label();
this.lblCompany = new System.Windows. Forms.Label();
this.lblCompany ID = new System.Windows. Forms.Label();
this.oleDbDataA dapterCompanyEd it = new
System.Data.Ole Db.OleDbDataAda pter();
this.oleDbDelet eCommand1 = new System.Data.Ole Db.OleDbCommand ();
this.oleDbConne ction1 = new System.Data.Ole Db.OleDbConnect ion();
this.oleDbInser tCommand1 = new System.Data.Ole Db.OleDbCommand ();
this.oleDbSelec tCommand1 = new System.Data.Ole Db.OleDbCommand ();
this.oleDbUpdat eCommand1 = new System.Data.Ole Db.OleDbCommand ();
this.cbActive = new System.Windows. Forms.CheckBox( );
((System.Compon entModel.ISuppo rtInitialize)(t his.dsCompanyEd it1)).BeginInit ();
this.SuspendLay out();
//
// dsCompanyEdit1
//
this.dsCompanyE dit1.DataSetNam e = "dsCompanyEdit" ;
this.dsCompanyE dit1.Locale = new System.Globaliz ation.CultureIn fo("en-US");
//
// btnCancel
//
this.btnCancel. DialogResult = System.Windows. Forms.DialogRes ult.Cancel;
this.btnCancel. Location = new System.Drawing. Point(280, 88);
this.btnCancel. Name = "btnCancel" ;
this.btnCancel. TabIndex = 18;
this.btnCancel. Text = "Cancel";
this.btnCancel. Click += new System.EventHan dler(this.btnCa ncel_Click);
//
// btnSave
//
this.btnSave.Lo cation = new System.Drawing. Point(184, 88);
this.btnSave.Na me = "btnSave";
this.btnSave.Ta bIndex = 17;
this.btnSave.Te xt = "Save";
this.btnSave.Cl ick += new System.EventHan dler(this.btnSa ve_Click);
//
// txtCompany
//
this.txtCompany .DataBindings.A dd(new System.Windows. Forms.Binding(" Text",
this.dsCompanyE dit1, "tblCompany.Com pany"));
this.txtCompany .Location = new System.Drawing. Point(80, 32);
this.txtCompany .Name = "txtCompany ";
this.txtCompany .Size = new System.Drawing. Size(272, 20);
this.txtCompany .TabIndex = 15;
this.txtCompany .Text = "";
//
// txtCompanyID
//
this.txtCompany ID.DataBindings .Add(new
System.Windows. Forms.Binding(" Text", this.dsCompanyE dit1,
"tblCompany.Com panyId"));
this.txtCompany ID.Location = new System.Drawing. Point(80, 8);
this.txtCompany ID.MaxLength = 1;
this.txtCompany ID.Name = "txtCompany ID";
this.txtCompany ID.Size = new System.Drawing. Size(24, 20);
this.txtCompany ID.TabIndex = 14;
this.txtCompany ID.Text = "";
//
// lblActive
//
this.lblActive. Location = new System.Drawing. Point(8, 56);
this.lblActive. Name = "lblActive" ;
this.lblActive. Size = new System.Drawing. Size(72, 23);
this.lblActive. TabIndex = 21;
this.lblActive. Text = "Active";
//
// lblCompany
//
this.lblCompany .Location = new System.Drawing. Point(8, 32);
this.lblCompany .Name = "lblCompany ";
this.lblCompany .Size = new System.Drawing. Size(72, 23);
this.lblCompany .TabIndex = 20;
this.lblCompany .Text = "Company";
//
// lblCompanyID
//
this.lblCompany ID.Location = new System.Drawing. Point(8, 8);
this.lblCompany ID.Name = "lblCompany ID";
this.lblCompany ID.Size = new System.Drawing. Size(72, 23);
this.lblCompany ID.TabIndex = 19;
this.lblCompany ID.Text = "Company ID";
//
// oleDbDataAdapte rCompanyEdit
//
this.oleDbDataA dapterCompanyEd it.DeleteComman d = this.oleDbDelet eCommand1;
this.oleDbDataA dapterCompanyEd it.InsertComman d = this.oleDbInser tCommand1;
this.oleDbDataA dapterCompanyEd it.SelectComman d = this.oleDbSelec tCommand1;
this.oleDbDataA dapterCompanyEd it.TableMapping s.AddRange(new
System.Data.Com mon.DataTableMa pping[] {
new
System.Data.Com mon.DataTableMa pping("Table", "tblCompany ", new
System.Data.Com mon.DataColumnM apping[] {
new
System.Data.Com mon.DataColumnM apping("Company Id", "CompanyId" ),
new
System.Data.Com mon.DataColumnM apping("Company ", "Company"),
new
System.Data.Com mon.DataColumnM apping("Active" , "Active")}) });
this.oleDbDataA dapterCompanyEd it.UpdateComman d = this.oleDbUpdat eCommand1;
//
// oleDbDeleteComm and1
//
this.oleDbDelet eCommand1.Comma ndText = "DELETE FROM tblCompany WHERE
(CompanyId = ?) AND (Active = ?) AND (Company = ?)";
this.oleDbDelet eCommand1.Conne ction = this.oleDbConne ction1;
this.oleDbDelet eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Co mpanyId",
System.Data.Ole Db.OleDbType.Va rWChar, 1,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "CompanyId" , System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbDelet eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Ac tive",
System.Data.Ole Db.OleDbType.Bo olean, 2, System.Data.Par ameterDirection .Input,
false, ((System.Byte)( 0)), ((System.Byte)( 0)), "Active",
System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbDelet eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Co mpany",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "Company", System.Data.Dat aRowVersion.Ori ginal, null));
//
// oleDbConnection 1
//
this.oleDbConne ction1.Connecti onString = @"Jet OLEDB:Global Partial Bulk
Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Data
Source=""C:\Esp Thr.mdb"";Jet OLEDB:Engine
Type=5;Provider =""Microsoft.Je t.OLEDB.4.0"";J et OLEDB:System database=;Jet
OLEDB:SFP=False ;persist security info=False;Exte nded Properties=;Mod e=Share
Deny None;Jet OLEDB:Encrypt Database=False; Jet OLEDB:Create System
Database=False; Jet OLEDB:Don't Copy Locale on Compact=False;J et OLEDB:Compact
Without Replica Repair=False;Us er ID=<omitted>;Je t OLEDB:Global Bulk
Transactions=1" ;
//
// oleDbInsertComm and1
//
this.oleDbInser tCommand1.Comma ndText = "INSERT INTO tblCompany(Comp anyId,
Company, Active) VALUES (?, ?, ?)";
this.oleDbInser tCommand1.Conne ction = this.oleDbConne ction1;
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("CompanyId" ,
System.Data.Ole Db.OleDbType.Va rWChar, 1, "CompanyId" ));
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Company",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Company")) ;
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Active",
System.Data.Ole Db.OleDbType.Bo olean, 2, "Active"));
//
// oleDbSelectComm and1
//
this.oleDbSelec tCommand1.Comma ndText = "SELECT CompanyId, Company, Active
FROM tblCompany";
this.oleDbSelec tCommand1.Conne ction = this.oleDbConne ction1;
//
// oleDbUpdateComm and1
//
this.oleDbUpdat eCommand1.Comma ndText = "UPDATE tblCompany SET CompanyId =
?, Company = ?, Active = ? WHERE (CompanyId = ?" +
") AND (Active = ?) AND (Company = ?)";
this.oleDbUpdat eCommand1.Conne ction = this.oleDbConne ction1;
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("CompanyId" ,
System.Data.Ole Db.OleDbType.Va rWChar, 1, "CompanyId" ));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Company",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Company")) ;
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Active",
System.Data.Ole Db.OleDbType.Bo olean, 2, "Active"));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Co mpanyId",
System.Data.Ole Db.OleDbType.Va rWChar, 1,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "CompanyId" , System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Ac tive",
System.Data.Ole Db.OleDbType.Bo olean, 2, System.Data.Par ameterDirection .Input,
false, ((System.Byte)( 0)), ((System.Byte)( 0)), "Active",
System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Co mpany",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "Company", System.Data.Dat aRowVersion.Ori ginal, null));
//
// cbActive
//
this.cbActive.D ataBindings.Add (new
System.Windows. Forms.Binding(" Checked", this.dsCompanyE dit1,
"tblCompany.Act ive"));
this.cbActive.L ocation = new System.Drawing. Point(80, 56);
this.cbActive.N ame = "cbActive";
this.cbActive.T abIndex = 22;
//
// frmCompanyEdit
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(360, 118);
this.Controls.A dd(this.cbActiv e);
this.Controls.A dd(this.btnCanc el);
this.Controls.A dd(this.btnSave );
this.Controls.A dd(this.txtComp any);
this.Controls.A dd(this.txtComp anyID);
this.Controls.A dd(this.lblActi ve);
this.Controls.A dd(this.lblComp any);
this.Controls.A dd(this.lblComp anyID);
this.Name = "frmCompanyEdit ";
this.Text = "frmCompanyEdit ";
this.Load += new System.EventHan dler(this.frmCo mpanyEdit_Load) ;
((System.Compon entModel.ISuppo rtInitialize)(t his.dsCompanyEd it1)).EndInit() ;
this.ResumeLayo ut(false);

}
#endregion

private void frmCompanyEdit_ Load(object sender, System.EventArg s e)
{
strCommandText = "SELECT CompanyID, Company, Active FROM tblCompany WHERE
CompanyID = '" + strCurrent + "'";
this.oleDbSelec tCommand1.Comma ndText = strCommandText;
oleDbDataAdapte rCompanyEdit.Fi ll(dsCompanyEdi t1);
// dgCompanyEdit.D ataSource = dsCompanyEdit1. Tables["tblCompany "];
// ((DataView)cm.L ist).AllowNew = false;
}

private void btnSave_Click(o bject sender, System.EventArg s e)
{
// DataRow cRow = catDS.Tables["Categories "].Rows[0];
// cRow["CategoryNa me"] = "New Category";
// catDA.Update(ca tDS);
if ((this.txtCompa nyID.Text == "") || (this.txtCompan y.Text == ""))
{
MessageBox.Show ("Informatio n may not be blank", "Problem Saving",
MessageBoxButto ns.OK, MessageBoxIcon. Exclamation,
MessageBoxDefau ltButton.Button 1);
this.txtCompany ID.Focus();
}
else
{
try
{
CurrencyManager cm =
(CurrencyManage r)this.BindingC ontext[dsCompanyEdit1, "tblCompany "];
cm.EndCurrentEd it();
oleDbDataAdapte rCompanyEdit.Up date(dsCompanyE dit1,"tblCompan y");
MessageBox.Show ("Database Updated!");
dsCompanyEdit1. Clear();
oleDbDataAdapte rCompanyEdit.Fi ll(dsCompanyEdi t1);
this.Close();
}
catch(Exception ex)
{
MessageBox.Show (ex.Message, ex.GetType().To String());
this.txtCompany ID.Focus();
}
}

}

private void btnCancel_Click (object sender, System.EventArg s e)
{
this.Close();
}

}
}

Thanks again,
Pam
Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
22506
by: Michael Walton | last post by:
I am trying to write some code that inserts or updates a text field in my SQL Server 2000 database. The SQL statement is created using a submit from a form, and the text is coming from a <textarea>, and therefore being placed into the SQL statement via a Request("field"). However, due to limitations in SQL Server 2000 and text fields, I can not use a simple Update or Insert command with text over 8000 bytes. Does anybody have any...
4
10714
by: Rob | last post by:
Hey, I'm pretty new to MySQL and have a question. I've built a database locally and have inputed some information. I need to go back and update some records, specifically by taking long pieces of text and putting them into text fields. Cutting and pasting in the command prompt for windows isn't such a good idea. Is there a way to update an existing record by importing a text file into a text field?
8
2714
by: threepins | last post by:
Hi, I have a website using a SQL Server database to store all of it's data. Retrieving data and writing basic data back is fine, however, when i go to update one table that has a text field in it the update fails if the amount of data being passed to the text field is too large. Is there a way around this or a particular update i should be using? Any information would be greatly appreciated.
11
2043
by: Woody Splawn | last post by:
Are there any problems with saving values to a database from a text field that has an apostrophy in it? I am using SQL Server 2000. My notes are not clear on this, but I seem to remember that if you save a value to a char or varchar field in the database and it (the text field) contains an apostropy in it, it can create problems. Does someone know what I am referring to and if so what are the issues and where can I find more information?
2
2339
by: Ville Mattila | last post by:
Hi there, I will post my question to this group too bacause the .data group seems to be rather quiet. I've been playing with VB.NET and ADO for a week now and find the different data handling functions very easy and nice. Anyway, I'm afraid that I haven't understood the data binding things correct. I'm using MySQL Connector/.NET to access my database from the
5
1558
by: plenahan68 | last post by:
I've made a small vb.net program to read my database and delete records that are specific to my needs. Well, the program says it's complete but nothing is deleted from my database. I've listed the code below. Imports System.data.oledb Imports System.Data Public Class Form1 Inherits System.Windows.Forms.Form Public Enum etif efilename = 0
1
4830
by: Ben Ramsey | last post by:
I'm using PostgreSQL on a Windows 2000 server and cygwin. All is set up just fine. The database works just fine, and ASP is connecting to the database through a DSN just fine. The only problem I seem to have is adding a large amount of text to a text column in the database. I can enter up to 8,118 characters (including spaces), but when I go over that amount, I receive the following error: Microsoft OLE DB Provider for ODBC Drivers...
0
1046
by: Jacob Donajkowski | last post by:
I want to change the text inside a textbox that is inside a loginview but it won't work using the .findcontrol function. I have tried : textbox tb = loginview1.findcontrol("textbox1"); tb.text = "New String"; but that dones't work for me. Can anyone help?
4
1867
by: Ruben | last post by:
Hi, I have a continuous form that provides a listing of various instruments that are serviced on a monthly to annual basis, with general info about the instrument, last and next service dates, etc. What I am trying to do is create an On Open event procedure that will identify all instruments that are listed with a string of either "Past Due" or "Schedule Vendor" based on whether each of their respective
0
8739
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9238
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9157
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9088
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5995
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3207
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2147
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.