473,848 Members | 1,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Issue with Databinding.

I am struck up with a problem and want anyone here to help me out. I am a
beginner in .NET trying to learng DataBinding concepts. I have binded 4 text
boxes with a dataset but when I say adapter.update it gives me 0 records
updated! I am not getting any exceptions. Below is the complete code. Someone
please help me out.

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

namespace ADO.NET
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmMain : System.Windows. Forms.Form
{
private System.Windows. Forms.Label lblEmpName;
private System.Windows. Forms.Label lblEmplId;
private System.Windows. Forms.Label lblDesignation;
private System.Windows. Forms.Label lblSex;
private System.Windows. Forms.TextBox txtEmpName;
private System.Windows. Forms.TextBox txtEmpID;
private System.Windows. Forms.TextBox txtDesignation;
private System.Windows. Forms.TextBox txtSex;
private System.Windows. Forms.Button btnDelete;
private System.Windows. Forms.Button btnInsert;
private System.Windows. Forms.Button btnUpdate;
private System.Windows. Forms.GroupBox grpSeek;
private System.Windows. Forms.GroupBox grpModify;
private System.Windows. Forms.Button btnPrevious;
private System.Windows. Forms.Button btnNext;
private System.Windows. Forms.Button btnLast;
private System.Windows. Forms.Button btnFirst;
private System.Windows. Forms.GroupBox grpData;
private System.Data.Sql Client.SqlDataA dapter sqlDataAdapter1 ;
private System.Data.Sql Client.SqlComma nd sqlSelectComman d1;
private System.Data.Sql Client.SqlComma nd sqlInsertComman d1;
private System.Data.Sql Client.SqlComma nd sqlUpdateComman d1;
private System.Data.Sql Client.SqlComma nd sqlDeleteComman d1;
private System.Data.Sql Client.SqlConne ction sqlConnection1;
private ADO.NET.DataSet 1 dataSet11;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

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

//
// 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.lblEmpName = new System.Windows. Forms.Label();
this.lblEmplId = new System.Windows. Forms.Label();
this.lblDesigna tion = new System.Windows. Forms.Label();
this.lblSex = new System.Windows. Forms.Label();
this.txtEmpName = new System.Windows. Forms.TextBox() ;
this.dataSet11 = new ADO.NET.DataSet 1();
this.txtEmpID = new System.Windows. Forms.TextBox() ;
this.txtDesigna tion = new System.Windows. Forms.TextBox() ;
this.txtSex = new System.Windows. Forms.TextBox() ;
this.btnPreviou s = new System.Windows. Forms.Button();
this.btnNext = new System.Windows. Forms.Button();
this.btnDelete = new System.Windows. Forms.Button();
this.btnInsert = new System.Windows. Forms.Button();
this.btnUpdate = new System.Windows. Forms.Button();
this.grpSeek = new System.Windows. Forms.GroupBox( );
this.btnFirst = new System.Windows. Forms.Button();
this.btnLast = new System.Windows. Forms.Button();
this.grpModify = new System.Windows. Forms.GroupBox( );
this.grpData = new System.Windows. Forms.GroupBox( );
this.sqlDataAda pter1 = new System.Data.Sql Client.SqlDataA dapter();
this.sqlDeleteC ommand1 = new System.Data.Sql Client.SqlComma nd();
this.sqlConnect ion1 = new System.Data.Sql Client.SqlConne ction();
this.sqlInsertC ommand1 = new System.Data.Sql Client.SqlComma nd();
this.sqlSelectC ommand1 = new System.Data.Sql Client.SqlComma nd();
this.sqlUpdateC ommand1 = new System.Data.Sql Client.SqlComma nd();
((System.Compon entModel.ISuppo rtInitialize)(t his.dataSet11)) .BeginInit();
this.grpSeek.Su spendLayout();
this.grpModify. SuspendLayout() ;
this.grpData.Su spendLayout();
this.SuspendLay out();
//
// lblEmpName
//
this.lblEmpName .AutoSize = true;
this.lblEmpName .Location = new System.Drawing. Point(8, 24);
this.lblEmpName .Name = "lblEmpName ";
this.lblEmpName .Size = new System.Drawing. Size(88, 16);
this.lblEmpName .TabIndex = 0;
this.lblEmpName .Text = "Employee Name";
//
// lblEmplId
//
this.lblEmplId. AutoSize = true;
this.lblEmplId. Location = new System.Drawing. Point(8, 64);
this.lblEmplId. Name = "lblEmplId" ;
this.lblEmplId. Size = new System.Drawing. Size(67, 16);
this.lblEmplId. TabIndex = 0;
this.lblEmplId. Text = "Employee Id";
//
// lblDesignation
//
this.lblDesigna tion.AutoSize = true;
this.lblDesigna tion.Location = new System.Drawing. Point(8, 104);
this.lblDesigna tion.Name = "lblDesignation ";
this.lblDesigna tion.Size = new System.Drawing. Size(64, 16);
this.lblDesigna tion.TabIndex = 0;
this.lblDesigna tion.Text = "Designatio n";
//
// lblSex
//
this.lblSex.Aut oSize = true;
this.lblSex.Loc ation = new System.Drawing. Point(8, 144);
this.lblSex.Nam e = "lblSex";
this.lblSex.Siz e = new System.Drawing. Size(24, 16);
this.lblSex.Tab Index = 0;
this.lblSex.Tex t = "Sex";
//
// txtEmpName
//
this.txtEmpName .BorderStyle = System.Windows. Forms.BorderSty le.FixedSingle;
this.txtEmpName .DataBindings.A dd(new System.Windows. Forms.Binding(" Text",
this.dataSet11, "Employee.Emplo yee"));
this.txtEmpName .Location = new System.Drawing. Point(104, 24);
this.txtEmpName .Name = "txtEmpName ";
this.txtEmpName .Size = new System.Drawing. Size(96, 20);
this.txtEmpName .TabIndex = 1;
this.txtEmpName .Text = "";
//
// dataSet11
//
this.dataSet11. DataSetName = "DataSet1";
this.dataSet11. Locale = new System.Globaliz ation.CultureIn fo("en-US");
//
// txtEmpID
//
this.txtEmpID.B orderStyle = System.Windows. Forms.BorderSty le.FixedSingle;
this.txtEmpID.D ataBindings.Add (new System.Windows. Forms.Binding(" Text",
this.dataSet11, "Employee.EmpId "));
this.txtEmpID.L ocation = new System.Drawing. Point(104, 64);
this.txtEmpID.N ame = "txtEmpID";
this.txtEmpID.S ize = new System.Drawing. Size(96, 20);
this.txtEmpID.T abIndex = 1;
this.txtEmpID.T ext = "";
//
// txtDesignation
//
this.txtDesigna tion.BorderStyl e =
System.Windows. Forms.BorderSty le.FixedSingle;
this.txtDesigna tion.DataBindin gs.Add(new
System.Windows. Forms.Binding(" Text", this.dataSet11, "Employee.Desig nation"));
this.txtDesigna tion.Location = new System.Drawing. Point(104, 104);
this.txtDesigna tion.Name = "txtDesignation ";
this.txtDesigna tion.Size = new System.Drawing. Size(96, 20);
this.txtDesigna tion.TabIndex = 1;
this.txtDesigna tion.Text = "";
//
// txtSex
//
this.txtSex.Bor derStyle = System.Windows. Forms.BorderSty le.FixedSingle;
this.txtSex.Dat aBindings.Add(n ew System.Windows. Forms.Binding(" Text",
this.dataSet11, "Employee.Sex") );
this.txtSex.Loc ation = new System.Drawing. Point(104, 144);
this.txtSex.Nam e = "txtSex";
this.txtSex.Siz e = new System.Drawing. Size(96, 20);
this.txtSex.Tab Index = 1;
this.txtSex.Tex t = "";
//
// btnPrevious
//
this.btnPreviou s.Location = new System.Drawing. Point(56, 24);
this.btnPreviou s.Name = "btnPreviou s";
this.btnPreviou s.Size = new System.Drawing. Size(32, 23);
this.btnPreviou s.TabIndex = 2;
this.btnPreviou s.Text = "<";
this.btnPreviou s.Click += new System.EventHan dler(this.btnPr evious_Click);
//
// btnNext
//
this.btnNext.Lo cation = new System.Drawing. Point(112, 24);
this.btnNext.Na me = "btnNext";
this.btnNext.Si ze = new System.Drawing. Size(32, 23);
this.btnNext.Ta bIndex = 3;
this.btnNext.Te xt = ">";
this.btnNext.Cl ick += new System.EventHan dler(this.btnNe xt_Click);
//
// btnDelete
//
this.btnDelete. Location = new System.Drawing. Point(112, 24);
this.btnDelete. Name = "btnDelete" ;
this.btnDelete. Size = new System.Drawing. Size(80, 23);
this.btnDelete. TabIndex = 4;
this.btnDelete. Text = "Delete";
//
// btnInsert
//
this.btnInsert. Location = new System.Drawing. Point(8, 64);
this.btnInsert. Name = "btnInsert" ;
this.btnInsert. Size = new System.Drawing. Size(184, 23);
this.btnInsert. TabIndex = 5;
this.btnInsert. Text = "Insert";
//
// btnUpdate
//
this.btnUpdate. Location = new System.Drawing. Point(8, 24);
this.btnUpdate. Name = "btnUpdate" ;
this.btnUpdate. Size = new System.Drawing. Size(80, 23);
this.btnUpdate. TabIndex = 6;
this.btnUpdate. Text = "Update";
this.btnUpdate. Click += new System.EventHan dler(this.btnUp date_Click);
//
// grpSeek
//
this.grpSeek.Co ntrols.Add(this .btnFirst);
this.grpSeek.Co ntrols.Add(this .btnLast);
this.grpSeek.Co ntrols.Add(this .btnNext);
this.grpSeek.Co ntrols.Add(this .btnPrevious);
this.grpSeek.Lo cation = new System.Drawing. Point(224, 8);
this.grpSeek.Na me = "grpSeek";
this.grpSeek.Si ze = new System.Drawing. Size(200, 72);
this.grpSeek.Ta bIndex = 7;
this.grpSeek.Ta bStop = false;
this.grpSeek.Te xt = "Seek";
//
// btnFirst
//
this.btnFirst.L ocation = new System.Drawing. Point(8, 24);
this.btnFirst.N ame = "btnFirst";
this.btnFirst.S ize = new System.Drawing. Size(32, 23);
this.btnFirst.T abIndex = 5;
this.btnFirst.T ext = "|<<";
this.btnFirst.C lick += new System.EventHan dler(this.btnFi rst_Click);
//
// btnLast
//
this.btnLast.Lo cation = new System.Drawing. Point(160, 24);
this.btnLast.Na me = "btnLast";
this.btnLast.Si ze = new System.Drawing. Size(32, 23);
this.btnLast.Ta bIndex = 4;
this.btnLast.Te xt = ">>|";
this.btnLast.Cl ick += new System.EventHan dler(this.btnLa st_Click);
//
// grpModify
//
this.grpModify. Controls.Add(th is.btnUpdate);
this.grpModify. Controls.Add(th is.btnDelete);
this.grpModify. Controls.Add(th is.btnInsert);
this.grpModify. Location = new System.Drawing. Point(224, 88);
this.grpModify. Name = "grpModify" ;
this.grpModify. Size = new System.Drawing. Size(200, 96);
this.grpModify. TabIndex = 8;
this.grpModify. TabStop = false;
this.grpModify. Text = "Modify";
//
// grpData
//
this.grpData.Co ntrols.Add(this .txtSex);
this.grpData.Co ntrols.Add(this .lblSex);
this.grpData.Co ntrols.Add(this .txtDesignation );
this.grpData.Co ntrols.Add(this .lblDesignation );
this.grpData.Co ntrols.Add(this .lblEmplId);
this.grpData.Co ntrols.Add(this .txtEmpName);
this.grpData.Co ntrols.Add(this .txtEmpID);
this.grpData.Co ntrols.Add(this .lblEmpName);
this.grpData.Lo cation = new System.Drawing. Point(8, 8);
this.grpData.Na me = "grpData";
this.grpData.Si ze = new System.Drawing. Size(208, 176);
this.grpData.Ta bIndex = 9;
this.grpData.Ta bStop = false;
this.grpData.Te xt = "Data";
//
// sqlDataAdapter1
//
this.sqlDataAda pter1.DeleteCom mand = this.sqlDeleteC ommand1;
this.sqlDataAda pter1.InsertCom mand = this.sqlInsertC ommand1;
this.sqlDataAda pter1.SelectCom mand = this.sqlSelectC ommand1;
this.sqlDataAda pter1.TableMapp ings.AddRange(n ew
System.Data.Com mon.DataTableMa pping[] {
new System.Data.Com mon.DataTableMa pping("Table",
"Employee", new System.Data.Com mon.DataColumnM apping[] {
new
System.Data.Com mon.DataColumnM apping("Employe e", "Employee") ,
new
System.Data.Com mon.DataColumnM apping("EmpId", "EmpId"),
new
System.Data.Com mon.DataColumnM apping("Sex", "Sex"),
new
System.Data.Com mon.DataColumnM apping("Designa tion", "Designation")} )});
this.sqlDataAda pter1.UpdateCom mand = this.sqlUpdateC ommand1;
//
// sqlDeleteComman d1
//
this.sqlDeleteC ommand1.Command Text = @"DELETE FROM Employee WHERE (EmpId
= @Original_EmpId ) AND (Designation = @Original_Desig nation OR
@Original_Desig nation IS NULL AND Designation IS NULL) AND (Employee =
@Original_Emplo yee OR @Original_Emplo yee IS NULL AND Employee IS NULL) AND
(Sex = @Original_Sex OR @Original_Sex IS NULL AND Sex IS NULL)";
this.sqlDeleteC ommand1.Connect ion = this.sqlConnect ion1;
this.sqlDeleteC ommand1.Paramet ers.Add(new
System.Data.Sql Client.SqlParam eter("@Original _EmpId",
System.Data.Sql DbType.Decimal, 9, System.Data.Par ameterDirection .Input,
false, ((System.Byte)( 18)), ((System.Byte)( 0)), "EmpId",
System.Data.Dat aRowVersion.Ori ginal, null));
this.sqlDeleteC ommand1.Paramet ers.Add(new
System.Data.Sql Client.SqlParam eter("@Original _Designation",
System.Data.Sql DbType.VarChar, 50, System.Data.Par ameterDirection .Input,
false, ((System.Byte)( 0)), ((System.Byte)( 0)), "Designatio n",
System.Data.Dat aRowVersion.Ori ginal, null));
this.sqlDeleteC ommand1.Paramet ers.Add(new
System.Data.Sql Client.SqlParam eter("@Original _Employee",
System.Data.Sql DbType.VarChar, 50, System.Data.Par ameterDirection .Input,
false, ((System.Byte)( 0)), ((System.Byte)( 0)), "Employee",
System.Data.Dat aRowVersion.Ori ginal, null));
this.sqlDeleteC ommand1.Paramet ers.Add(new
System.Data.Sql Client.SqlParam eter("@Original _Sex",
System.Data.Sql DbType.VarChar, 10, System.Data.Par ameterDirection .Input,
false, ((System.Byte)( 0)), ((System.Byte)( 0)), "Sex",
System.Data.Dat aRowVersion.Ori ginal, null));
//
// sqlConnection1
//
this.sqlConnect ion1.Connection String = "workstatio n
id=\"B3-AVON-HF04\";packet size=4096;user id=sa;data source=\".\";pe rsist" +
" security info=False;init ial catalog=Gokul";
//
// sqlInsertComman d1
//
this.sqlInsertC ommand1.Command Text = "INSERT INTO Employee(Employ ee,
EmpId, Sex, Designation) VALUES (@Employee, @EmpId" +
", @Sex, @Designation); SELECT Employee, EmpId, Sex, Designation FROM
Employee WH" +
"ERE (EmpId = @EmpId)";
this.sqlInsertC ommand1.Connect ion = this.sqlConnect ion1;
this.sqlInsertC ommand1.Paramet ers.Add(new
System.Data.Sql Client.SqlParam eter("@Employee ",
System.Data.Sql DbType.VarChar, 50, "Employee") );
this.sqlInsertC ommand1.Paramet ers.Add(new
System.Data.Sql Client.SqlParam eter("@EmpId", System.Data.Sql DbType.Decimal,
9, System.Data.Par ameterDirection .Input, false, ((System.Byte)( 18)),
((System.Byte)( 0)), "EmpId", System.Data.Dat aRowVersion.Cur rent, null));
this.sqlInsertC ommand1.Paramet ers.Add(new
System.Data.Sql Client.SqlParam eter("@Sex", System.Data.Sql DbType.VarChar, 10,
"Sex"));
this.sqlInsertC ommand1.Paramet ers.Add(new
System.Data.Sql Client.SqlParam eter("@Designat ion",
System.Data.Sql DbType.VarChar, 50, "Designation")) ;
//
// sqlSelectComman d1
//
this.sqlSelectC ommand1.Command Text = "SELECT Employee, EmpId, Sex,
Designation FROM Employee";
this.sqlSelectC ommand1.Connect ion = this.sqlConnect ion1;
//
// sqlUpdateComman d1
//
this.sqlUpdateC ommand1.Command Text = @"UPDATE Employee SET Employee =
@Employee, EmpId = @EmpId, Sex = @Sex, Designation = @Designation WHERE
(EmpId = @Original_EmpId ) AND (Designation = @Original_Desig nation OR
@Original_Desig nation IS NULL AND Designation IS NULL) AND (Employee =
@Original_Emplo yee OR @Original_Emplo yee IS NULL AND Employee IS NULL) AND
(Sex = @Original_Sex OR @Original_Sex IS NULL AND Sex IS NULL); SELECT
Employee, EmpId, Sex, Designation FROM Employee WHERE (EmpId = @EmpId)";
this.sqlUpdateC ommand1.Connect ion = this.sqlConnect ion1;
this.sqlUpdateC ommand1.Paramet ers.Add(new
System.Data.Sql Client.SqlParam eter("@Employee ",
System.Data.Sql DbType.VarChar, 50, "Employee") );
this.sqlUpdateC ommand1.Paramet ers.Add(new
System.Data.Sql Client.SqlParam eter("@EmpId", System.Data.Sql DbType.Decimal,
9, System.Data.Par ameterDirection .Input, false, ((System.Byte)( 18)),
((System.Byte)( 0)), "EmpId", System.Data.Dat aRowVersion.Cur rent, null));
this.sqlUpdateC ommand1.Paramet ers.Add(new
System.Data.Sql Client.SqlParam eter("@Sex", System.Data.Sql DbType.VarChar, 10,
"Sex"));
this.sqlUpdateC ommand1.Paramet ers.Add(new
System.Data.Sql Client.SqlParam eter("@Designat ion",
System.Data.Sql DbType.VarChar, 50, "Designation")) ;
this.sqlUpdateC ommand1.Paramet ers.Add(new
System.Data.Sql Client.SqlParam eter("@Original _EmpId",
System.Data.Sql DbType.Decimal, 9, System.Data.Par ameterDirection .Input,
false, ((System.Byte)( 18)), ((System.Byte)( 0)), "EmpId",
System.Data.Dat aRowVersion.Ori ginal, null));
this.sqlUpdateC ommand1.Paramet ers.Add(new
System.Data.Sql Client.SqlParam eter("@Original _Designation",
System.Data.Sql DbType.VarChar, 50, System.Data.Par ameterDirection .Input,
false, ((System.Byte)( 0)), ((System.Byte)( 0)), "Designatio n",
System.Data.Dat aRowVersion.Ori ginal, null));
this.sqlUpdateC ommand1.Paramet ers.Add(new
System.Data.Sql Client.SqlParam eter("@Original _Employee",
System.Data.Sql DbType.VarChar, 50, System.Data.Par ameterDirection .Input,
false, ((System.Byte)( 0)), ((System.Byte)( 0)), "Employee",
System.Data.Dat aRowVersion.Ori ginal, null));
this.sqlUpdateC ommand1.Paramet ers.Add(new
System.Data.Sql Client.SqlParam eter("@Original _Sex",
System.Data.Sql DbType.VarChar, 10, System.Data.Par ameterDirection .Input,
false, ((System.Byte)( 0)), ((System.Byte)( 0)), "Sex",
System.Data.Dat aRowVersion.Ori ginal, null));
//
// frmMain
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(432, 190);
this.Controls.A dd(this.grpData );
this.Controls.A dd(this.grpModi fy);
this.Controls.A dd(this.grpSeek );
this.MaximizeBo x = false;
this.MinimizeBo x = false;
this.Name = "frmMain";
this.StartPosit ion = System.Windows. Forms.FormStart Position.Center Screen;
this.Text = "Simple Data Binding";
this.Load += new System.EventHan dler(this.frmMa in_Load);
((System.Compon entModel.ISuppo rtInitialize)(t his.dataSet11)) .EndInit();
this.grpSeek.Re sumeLayout(fals e);
this.grpModify. ResumeLayout(fa lse);
this.grpData.Re sumeLayout(fals e);
this.ResumeLayo ut(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new frmMain());
}

private void frmMain_Load(ob ject sender, System.EventArg s e)
{
try
{

sqlDataAdapter1 .Fill ( dataSet11,"Empl oyee" ) ;

}

catch ( Exception Ex )
{

MessageBox.Show ( Ex.Message ) ;
}

}

private void btnNext_Click(o bject sender, System.EventArg s e)
{
try
{

if ( this.BindingCon text[dataSet11 , "Employee" ].Position !=
this.BindingCon text[dataSet11 , "Employee" ].Count - 1 )

this.BindingCon text[dataSet11 , "Employee" ].Position += 1 ;

else

MessageBox.Show ( "EOF reached" ) ;

}

catch ( Exception Ex )
{

MessageBox.Show ( Ex.Message ) ;
}

return ;
}

private void btnPrevious_Cli ck(object sender, System.EventArg s e)
{

try
{

if ( this.BindingCon text[dataSet11 , "Employee" ].Position != 0 )

this.BindingCon text[dataSet11 , "Employee" ].Position -= 1 ;

else

MessageBox.Show ( "EOB reached" ) ;

}

catch ( Exception Ex )
{

MessageBox.Show ( Ex.Message ) ;
}

return ;

}

private void btnFirst_Click( object sender, System.EventArg s e)
{
try
{

this.BindingCon text[dataSet11 , "Employee" ].Position = 0 ;

}

catch ( Exception Ex )
{

MessageBox.Show ( Ex.Message ) ;
}

return ;
}

private void btnLast_Click(o bject sender, System.EventArg s e)
{
try
{

this.BindingCon text[dataSet11 , "Employee" ].Position =
this.BindingCon text[dataSet11 , "Employee" ].Count - 1 ;

}

catch ( Exception Ex )
{

MessageBox.Show ( Ex.Message ) ;
}

return ;
}

private void btnUpdate_Click ( object sender, System.EventArg s e )
{

try
{

MessageBox.Show ( "Records Affected - " + sqlDataAdapter1 .Update(
dataSet11 ).ToString ( ) ) ;

}

catch ( Exception Ex )
{

MessageBox.Show ( Ex.Message ) ;
}

return ;

}

}
}

Jan 25 '07
11 1824
Adapter created all those command automatically! I didnt create them

"RobinS" wrote:
Did you create the Update, Insert, and Delete Command objects for your
adapter?

Robin S.
-------------------------------------------
"Gokul" <Go***@discussi ons.microsoft.c omwrote in message
news:D0******** *************** ***********@mic rosoft.com...
Robin I use SQL 2000 and adapter will create a connection for me.

"RobinS" wrote:
I don't suppose you're using a SQL Express database, are you? You might
want to check out this link I saw posted over in the ADO.Net newsgroup
about updating a different database than you think.

http://msdn2.microsoft.com/en-us/lib...89(VS.80).aspx

Robin S.
---------------------------------------------------------------------

"Gokul" <Go***@discussi ons.microsoft.c omwrote in message
news:AB******** *************** ***********@mic rosoft.com...
Thanks Robin.
I checked the database as well but no change,its same.

Checked the datarow state it is unchanged!

But when I printed the value dataSet11.Table s[0].Rows[0][0].ToString()
it
gives me the updated text!!!!

Can anyone please tell me what could be the problem

"RobinS" wrote:

When you say it is not updating the data source, are you relying on
your
display of the number of records updated, or are you actually
checking
the
database?

Can you check the state of the row, i.e. is it set to Unchanged, or
is
it set
to Modified?

Do your Adds work, and it's just the changes that don't work?
What about the Deletes?

Your code looks right, at least on first inspection.

Robin S.
---------------------------------------------------------

"Gokul" <Go***@discussi ons.microsoft.c omwrote in message
news:9B******** *************** ***********@mic rosoft.com...
I have tried using acceptchanges but same result! I have read some
where when
we use adapter.update it internally calls acceptchanges method.

When I change the text in the textbox and click next button, then
back
button, it shows the text with the changes! but when i say update
it
is not
updating the datasource. Why is this!!!!

"Marc Vangrieken" wrote:

Hi,

I haven't looked at your code very thoroughly but it looks as if
the
changes are not reflected in your dataset before you start the
update
method of your tableAdapter. Take a look at the AcceptChanges
method
on your DataSet...

http://msdn2.microsoft.com/en-us/lib...ptchanges.aspx

Kind regards,
On 25 jan, 08:39, Gokul <G...@discussio ns.microsoft.co mwrote:
I am struck up with a problem and want anyone here to help me
out.
I am a
beginner in .NET trying to learng DataBinding concepts. I have
binded 4 text
boxes with a dataset but when I say adapter.update it gives me 0
records
updated! I am not getting any exceptions. Below is the complete
code. Someone
please help me out.

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

namespace ADO.NET
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmMain : System.Windows. Forms.Form
{
private System.Windows. Forms.Label lblEmpName;
private System.Windows. Forms.Label lblEmplId;
private System.Windows. Forms.Label
lblDesignation;
private System.Windows. Forms.Label lblSex;
private System.Windows. Forms.TextBox txtEmpName;
private System.Windows. Forms.TextBox txtEmpID;
private System.Windows. Forms.TextBox
txtDesignation;
private System.Windows. Forms.TextBox txtSex;
private System.Windows. Forms.Button btnDelete;
private System.Windows. Forms.Button btnInsert;
private System.Windows. Forms.Button btnUpdate;
private System.Windows. Forms.GroupBox grpSeek;
private System.Windows. Forms.GroupBox grpModify;
private System.Windows. Forms.Button btnPrevious;
private System.Windows. Forms.Button btnNext;
private System.Windows. Forms.Button btnLast;
private System.Windows. Forms.Button btnFirst;
private System.Windows. Forms.GroupBox grpData;
private System.Data.Sql Client.SqlDataA dapter
sqlDataAdapter1 ;
private System.Data.Sql Client.SqlComma nd
sqlSelectComman d1;
private System.Data.Sql Client.SqlComma nd
sqlInsertComman d1;
private System.Data.Sql Client.SqlComma nd
sqlUpdateComman d1;
private System.Data.Sql Client.SqlComma nd
sqlDeleteComman d1;
private System.Data.Sql Client.SqlConne ction
sqlConnection1;
private ADO.NET.DataSet 1 dataSet11;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r
components
= null;

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

//
// 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.lblEmpName = new
System.Windows. Forms.Label();
this.lblEmplId = new
System.Windows. Forms.Label();
this.lblDesigna tion = new
System.Windows. Forms.Label();
this.lblSex = new
System.Windows. Forms.Label();
this.txtEmpName = new
System.Windows. Forms.TextBox() ;
this.dataSet11 = new ADO.NET.DataSet 1();
this.txtEmpID = new
System.Windows. Forms.TextBox() ;
this.txtDesigna tion = new
System.Windows. Forms.TextBox() ;
this.txtSex = new
System.Windows. Forms.TextBox() ;
this.btnPreviou s = new
System.Windows. Forms.Button();
this.btnNext = new
System.Windows. Forms.Button();
this.btnDelete = new
System.Windows. Forms.Button();
this.btnInsert = new
System.Windows. Forms.Button();
this.btnUpdate = new
System.Windows. Forms.Button();
this.grpSeek = new
System.Windows. Forms.GroupBox( );
this.btnFirst = new
System.Windows. Forms.Button();
this.btnLast = new
System.Windows. Forms.Button();
this.grpModify = new
System.Windows. Forms.GroupBox( );
this.grpData = new
System.Windows. Forms.GroupBox( );
this.sqlDataAda pter1 = new
System.Data.Sql Client.SqlDataA dapter();
this.sqlDeleteC ommand1 = new
System.Data.Sql Client.SqlComma nd();
this.sqlConnect ion1 = new
System.Data.Sql Client.SqlConne ction();
this.sqlInsertC ommand1 = new
System.Data.Sql Client.SqlComma nd();
this.sqlSelectC ommand1 = new
System.Data.Sql Client.SqlComma nd();
this.sqlUpdateC ommand1 = new
System.Data.Sql Client.SqlComma nd();

((System.Compon entModel.ISuppo rtInitialize)(t his.dataSet11)) .BeginInit();
this.grpSeek.Su spendLayout();
this.grpModify. SuspendLayout() ;
this.grpData.Su spendLayout();
this.SuspendLay out();
//
// lblEmpName
//
this.lblEmpName .AutoSize = true;
this.lblEmpName .Location = new
System.Drawing. Point(8, 24);
this.lblEmpName .Name = "lblEmpName ";
this.lblEmpName .Size = new
System.Drawing. Size(88, 16);
this.lblEmpName .TabIndex = 0;
this.lblEmpName .Text = "Employee Name";
//
// lblEmplId
//
this.lblEmplId. AutoSize = true;
this.lblEmplId. Location = new
System.Drawing. Point(8, 64);
this.lblEmplId. Name = "lblEmplId" ;
this.lblEmplId. Size = new
System.Drawing. Size(67, 16);
this.lblEmplId. TabIndex = 0;
this.lblEmplId. Text = "Employee Id";
//
// lblDesignation
//
this.lblDesigna tion.AutoSize = true;
this.lblDesigna tion.Location = new
System.Drawing. Point(8, 104);
this.lblDesigna tion.Name =
"lblDesignation ";
this.lblDesigna tion.Size = new
System.Drawing. Size(64, 16);
this.lblDesigna tion.TabIndex = 0;
this.lblDesigna tion.Text =
"Designatio n";
//
// lblSex
//
this.lblSex.Aut oSize = true;
this.lblSex.Loc ation = new
System.Drawing. Point(8, 144);
this.lblSex.Nam e = "lblSex";
this.lblSex.Siz e = new
System.Drawing. Size(24, 16);
this.lblSex.Tab Index = 0;
this.lblSex.Tex t = "Sex";
//
// txtEmpName
//
this.txtEmpName .BorderStyle =
System.Windows. Forms.BorderSty le.FixedSingle;
this.txtEmpName .DataBindings.A dd(new
System.Windows. Forms.Binding(" Text",
this.dataSet11, "Employee.Emplo yee"));
Jan 30 '07 #11
When you say the adapters created those commands, how did that happen? Are
you using Strongly Typed Datasets that you created with the DataSet
Designer? Or are you invoking the CommandBuilder?

Robin S.
-------------------------
"Gokul" <Go***@discussi ons.microsoft.c omwrote in message
news:F9******** *************** ***********@mic rosoft.com...
Adapter created all those command automatically! I didnt create them

"RobinS" wrote:
>Did you create the Update, Insert, and Delete Command objects for your
adapter?

Robin S.
-------------------------------------------
"Gokul" <Go***@discussi ons.microsoft.c omwrote in message
news:D0******* *************** ************@mi crosoft.com...
Robin I use SQL 2000 and adapter will create a connection for me.

"RobinS" wrote:

I don't suppose you're using a SQL Express database, are you? You
might
want to check out this link I saw posted over in the ADO.Net
newsgroup
about updating a different database than you think.

http://msdn2.microsoft.com/en-us/lib...89(VS.80).aspx

Robin S.
---------------------------------------------------------------------

"Gokul" <Go***@discussi ons.microsoft.c omwrote in message
news:AB******* *************** ************@mi crosoft.com...
Thanks Robin.
I checked the database as well but no change,its same.

Checked the datarow state it is unchanged!

But when I printed the value
dataSet11.Table s[0].Rows[0][0].ToString()
it
gives me the updated text!!!!

Can anyone please tell me what could be the problem

"RobinS" wrote:

When you say it is not updating the data source, are you relying
on
your
display of the number of records updated, or are you actually
checking
the
database?

Can you check the state of the row, i.e. is it set to Unchanged,
or
is
it set
to Modified?

Do your Adds work, and it's just the changes that don't work?
What about the Deletes?

Your code looks right, at least on first inspection.

Robin S.
---------------------------------------------------------

"Gokul" <Go***@discussi ons.microsoft.c omwrote in message
news:9B******* *************** ************@mi crosoft.com...
I have tried using acceptchanges but same result! I have read
some
where when
we use adapter.update it internally calls acceptchanges method.

When I change the text in the textbox and click next button,
then
back
button, it shows the text with the changes! but when i say
update
it
is not
updating the datasource. Why is this!!!!

"Marc Vangrieken" wrote:

Hi,

I haven't looked at your code very thoroughly but it looks as
if
the
changes are not reflected in your dataset before you start the
update
method of your tableAdapter. Take a look at the AcceptChanges
method
on your DataSet...

http://msdn2.microsoft.com/en-us/lib...ptchanges.aspx

Kind regards,
On 25 jan, 08:39, Gokul <G...@discussio ns.microsoft.co mwrote:
I am struck up with a problem and want anyone here to help me
out.
I am a
beginner in .NET trying to learng DataBinding concepts. I
have
binded 4 text
boxes with a dataset but when I say adapter.update it gives
me 0
records
updated! I am not getting any exceptions. Below is the
complete
code. Someone
please help me out.

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

namespace ADO.NET
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmMain : System.Windows. Forms.Form
{
private System.Windows. Forms.Label
lblEmpName;
private System.Windows. Forms.Label lblEmplId;
private System.Windows. Forms.Label
lblDesignation;
private System.Windows. Forms.Label lblSex;
private System.Windows. Forms.TextBox
txtEmpName;
private System.Windows. Forms.TextBox
txtEmpID;
private System.Windows. Forms.TextBox
txtDesignation;
private System.Windows. Forms.TextBox txtSex;
private System.Windows. Forms.Button
btnDelete;
private System.Windows. Forms.Button
btnInsert;
private System.Windows. Forms.Button
btnUpdate;
private System.Windows. Forms.GroupBox
grpSeek;
private System.Windows. Forms.GroupBox
grpModify;
private System.Windows. Forms.Button
btnPrevious;
private System.Windows. Forms.Button btnNext;
private System.Windows. Forms.Button btnLast;
private System.Windows. Forms.Button btnFirst;
private System.Windows. Forms.GroupBox
grpData;
private System.Data.Sql Client.SqlDataA dapter
sqlDataAdapter1 ;
private System.Data.Sql Client.SqlComma nd
sqlSelectComman d1;
private System.Data.Sql Client.SqlComma nd
sqlInsertComman d1;
private System.Data.Sql Client.SqlComma nd
sqlUpdateComman d1;
private System.Data.Sql Client.SqlComma nd
sqlDeleteComman d1;
private System.Data.Sql Client.SqlConne ction
sqlConnection1;
private ADO.NET.DataSet 1 dataSet11;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r
components
= null;

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

//
// 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.lblEmpName = new
System.Windows. Forms.Label();
this.lblEmplId = new
System.Windows. Forms.Label();
this.lblDesigna tion = new
System.Windows. Forms.Label();
this.lblSex = new
System.Windows. Forms.Label();
this.txtEmpName = new
System.Windows. Forms.TextBox() ;
this.dataSet11 = new
ADO.NET.DataSet 1();
this.txtEmpID = new
System.Windows. Forms.TextBox() ;
this.txtDesigna tion = new
System.Windows. Forms.TextBox() ;
this.txtSex = new
System.Windows. Forms.TextBox() ;
this.btnPreviou s = new
System.Windows. Forms.Button();
this.btnNext = new
System.Windows. Forms.Button();
this.btnDelete = new
System.Windows. Forms.Button();
this.btnInsert = new
System.Windows. Forms.Button();
this.btnUpdate = new
System.Windows. Forms.Button();
this.grpSeek = new
System.Windows. Forms.GroupBox( );
this.btnFirst = new
System.Windows. Forms.Button();
this.btnLast = new
System.Windows. Forms.Button();
this.grpModify = new
System.Windows. Forms.GroupBox( );
this.grpData = new
System.Windows. Forms.GroupBox( );
this.sqlDataAda pter1 = new
System.Data.Sql Client.SqlDataA dapter();
this.sqlDeleteC ommand1 = new
System.Data.Sql Client.SqlComma nd();
this.sqlConnect ion1 = new
System.Data.Sql Client.SqlConne ction();
this.sqlInsertC ommand1 = new
System.Data.Sql Client.SqlComma nd();
this.sqlSelectC ommand1 = new
System.Data.Sql Client.SqlComma nd();
this.sqlUpdateC ommand1 = new
System.Data.Sql Client.SqlComma nd();

((System.Compon entModel.ISuppo rtInitialize)(t his.dataSet11)) .BeginInit();
this.grpSeek.Su spendLayout();
this.grpModify. SuspendLayout() ;
this.grpData.Su spendLayout();
this.SuspendLay out();
//
// lblEmpName
//
this.lblEmpName .AutoSize = true;
this.lblEmpName .Location = new
System.Drawing. Point(8, 24);
this.lblEmpName .Name = "lblEmpName ";
this.lblEmpName .Size = new
System.Drawing. Size(88, 16);
this.lblEmpName .TabIndex = 0;
this.lblEmpName .Text = "Employee
Name";
//
// lblEmplId
//
this.lblEmplId. AutoSize = true;
this.lblEmplId. Location = new
System.Drawing. Point(8, 64);
this.lblEmplId. Name = "lblEmplId" ;
this.lblEmplId. Size = new
System.Drawing. Size(67, 16);
this.lblEmplId. TabIndex = 0;
this.lblEmplId. Text = "Employee Id";
//
// lblDesignation
//
this.lblDesigna tion.AutoSize = true;
this.lblDesigna tion.Location = new
System.Drawing. Point(8, 104);
this.lblDesigna tion.Name =
"lblDesignation ";
this.lblDesigna tion.Size = new
System.Drawing. Size(64, 16);
this.lblDesigna tion.TabIndex = 0;
this.lblDesigna tion.Text =
"Designatio n";
//
// lblSex
//
this.lblSex.Aut oSize = true;
this.lblSex.Loc ation = new
System.Drawing. Point(8, 144);
this.lblSex.Nam e = "lblSex";
this.lblSex.Siz e = new
System.Drawing. Size(24, 16);
this.lblSex.Tab Index = 0;
this.lblSex.Tex t = "Sex";
//
// txtEmpName
//
this.txtEmpName .BorderStyle =
System.Windows. Forms.BorderSty le.FixedSingle;
this.txtEmpName .DataBindings.A dd(new
System.Windows. Forms.Binding(" Text",
this.dataSet11, "Employee.Emplo yee"));

Jan 31 '07 #12

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

Similar topics

0
1478
by: Jeff | last post by:
I am having a behaviour problem with Databinding on a C# WinForm. I have three textboxes and a Checkbox bound to a dataset. The desired behaviour is when I check/uncheck the checkbox, I want to either enable, or disable and clear the corresponding textboxes. I want the fact that I cleared the text in the textboxes to reflect in the dataset, so I am calling the EndCurrentEdit() method on the currency manager to update the dataset within...
1
1371
by: Dotnet Newbie | last post by:
Hi all, I am working on .NET framework 1.1 While binding data to our master table in the database, we are using this System.Data.Relatedview class. But the issue is, it does not appropriately update data. The databinding is failing too. I traced down the issue to this particular class by manual debugging. I could also see a similar unanswered post in the same newsgroup :
0
7690
by: Timothy White | last post by:
I have a Windows Form Which Displays one record at a time. The DataTable object which is bound to the Form Controls only contains the record that is being displayed. When I need to display a different record, any changes in the current record are saved to an Access Database, the DataTable's Row Collection is Cleared and the New Record is read into the DataTable. (This is done to ensure that when the User goes to view a record, they get...
3
1680
by: LDD | last post by:
Hey folks I'm porting an app from VB6 to VB.Net... what a process! I'm about 70% of the way through. However I'm trying to find some information on how to upgrade the code snippet below to make use of ADO.Net -----------------------------------------------------
8
2192
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got answered... In 1.1 we always did our own myDataAdapter.fills and we liked that control for lots of good reasons. Now the new DataSource (or is it a TableAdapter:Dataset) automatically fills the Gridview. How can we control that fill? In a...
2
8747
by: P. Yanzick | last post by:
Hello, I am creating an edit template for a FormView control, changing one of the textboxes to a dropdown box. The dropdown will be populated from a simple table with the primary key, and a description (i.e. a colors table, so there is a colors ID and a color description). The data source the FormView is pulling data from stores (in this example) the primary key for the colors table. My ultimate goal is when the FormView goes into...
0
1104
by: bne | last post by:
Hi All, I have a shopping cart app that (I think) has broken due to an upgrade to .NET 2.0. Some products display fine: <http://ukweddinggroup.com/default.aspx?prd=11> Others display okay but validation on the dropdown list options break: <http://ukweddinggroup.com/default.aspx?prd=249>
1
2250
by: Alan Samet | last post by:
I know what's causing this, but how do I work around it? ********************** file: test.master: ********************** <%@ Master %> <script runat=server> void Page_Load(object sender, EventArgs e) {
3
1891
by: Peter | last post by:
Hi! I am having some very strange behavior with my databound controls. It's taken a long time to isolate exactly what is provoking the problem, but I'm still leagues away from solving it. I have a DataView which filters a DataSet. Bound to this dataview is a ListBox, via its DataSource property. The DisplayMember is the name property of the row. Simple enough so far?
0
1098
by: nelsonbrodyk | last post by:
Hey All, I have been able to set up a databinding to a property with the following code: <TextBox x:Name="txtTextBox" Text="{Binding Path=NameFirst, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/> and in the code: profile = context.NewProfile(); profile.NameFirst = "My Name"; txtTextBox.DataContext = profile;
0
9892
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10661
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
10718
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
10347
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...
1
7889
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7067
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
5731
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5917
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3172
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.