Issue with Databinding.

G

Guest

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.Collections;
using System.ComponentModel;
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.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private ADO.NET.DataSet1 dataSet11;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

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

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
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 InitializeComponent()
{
this.lblEmpName = new System.Windows.Forms.Label();
this.lblEmplId = new System.Windows.Forms.Label();
this.lblDesignation = new System.Windows.Forms.Label();
this.lblSex = new System.Windows.Forms.Label();
this.txtEmpName = new System.Windows.Forms.TextBox();
this.dataSet11 = new ADO.NET.DataSet1();
this.txtEmpID = new System.Windows.Forms.TextBox();
this.txtDesignation = new System.Windows.Forms.TextBox();
this.txtSex = new System.Windows.Forms.TextBox();
this.btnPrevious = 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.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.grpSeek.SuspendLayout();
this.grpModify.SuspendLayout();
this.grpData.SuspendLayout();
this.SuspendLayout();
//
// 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.lblDesignation.AutoSize = true;
this.lblDesignation.Location = new System.Drawing.Point(8, 104);
this.lblDesignation.Name = "lblDesignation";
this.lblDesignation.Size = new System.Drawing.Size(64, 16);
this.lblDesignation.TabIndex = 0;
this.lblDesignation.Text = "Designation";
//
// lblSex
//
this.lblSex.AutoSize = true;
this.lblSex.Location = new System.Drawing.Point(8, 144);
this.lblSex.Name = "lblSex";
this.lblSex.Size = new System.Drawing.Size(24, 16);
this.lblSex.TabIndex = 0;
this.lblSex.Text = "Sex";
//
// txtEmpName
//
this.txtEmpName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtEmpName.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.dataSet11, "Employee.Employee"));
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.Globalization.CultureInfo("en-US");
//
// txtEmpID
//
this.txtEmpID.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtEmpID.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.dataSet11, "Employee.EmpId"));
this.txtEmpID.Location = new System.Drawing.Point(104, 64);
this.txtEmpID.Name = "txtEmpID";
this.txtEmpID.Size = new System.Drawing.Size(96, 20);
this.txtEmpID.TabIndex = 1;
this.txtEmpID.Text = "";
//
// txtDesignation
//
this.txtDesignation.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.txtDesignation.DataBindings.Add(new
System.Windows.Forms.Binding("Text", this.dataSet11, "Employee.Designation"));
this.txtDesignation.Location = new System.Drawing.Point(104, 104);
this.txtDesignation.Name = "txtDesignation";
this.txtDesignation.Size = new System.Drawing.Size(96, 20);
this.txtDesignation.TabIndex = 1;
this.txtDesignation.Text = "";
//
// txtSex
//
this.txtSex.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtSex.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.dataSet11, "Employee.Sex"));
this.txtSex.Location = new System.Drawing.Point(104, 144);
this.txtSex.Name = "txtSex";
this.txtSex.Size = new System.Drawing.Size(96, 20);
this.txtSex.TabIndex = 1;
this.txtSex.Text = "";
//
// btnPrevious
//
this.btnPrevious.Location = new System.Drawing.Point(56, 24);
this.btnPrevious.Name = "btnPrevious";
this.btnPrevious.Size = new System.Drawing.Size(32, 23);
this.btnPrevious.TabIndex = 2;
this.btnPrevious.Text = "<";
this.btnPrevious.Click += new System.EventHandler(this.btnPrevious_Click);
//
// btnNext
//
this.btnNext.Location = new System.Drawing.Point(112, 24);
this.btnNext.Name = "btnNext";
this.btnNext.Size = new System.Drawing.Size(32, 23);
this.btnNext.TabIndex = 3;
this.btnNext.Text = ">";
this.btnNext.Click += new System.EventHandler(this.btnNext_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.EventHandler(this.btnUpdate_Click);
//
// grpSeek
//
this.grpSeek.Controls.Add(this.btnFirst);
this.grpSeek.Controls.Add(this.btnLast);
this.grpSeek.Controls.Add(this.btnNext);
this.grpSeek.Controls.Add(this.btnPrevious);
this.grpSeek.Location = new System.Drawing.Point(224, 8);
this.grpSeek.Name = "grpSeek";
this.grpSeek.Size = new System.Drawing.Size(200, 72);
this.grpSeek.TabIndex = 7;
this.grpSeek.TabStop = false;
this.grpSeek.Text = "Seek";
//
// btnFirst
//
this.btnFirst.Location = new System.Drawing.Point(8, 24);
this.btnFirst.Name = "btnFirst";
this.btnFirst.Size = new System.Drawing.Size(32, 23);
this.btnFirst.TabIndex = 5;
this.btnFirst.Text = "|<<";
this.btnFirst.Click += new System.EventHandler(this.btnFirst_Click);
//
// btnLast
//
this.btnLast.Location = new System.Drawing.Point(160, 24);
this.btnLast.Name = "btnLast";
this.btnLast.Size = new System.Drawing.Size(32, 23);
this.btnLast.TabIndex = 4;
this.btnLast.Text = ">>|";
this.btnLast.Click += new System.EventHandler(this.btnLast_Click);
//
// grpModify
//
this.grpModify.Controls.Add(this.btnUpdate);
this.grpModify.Controls.Add(this.btnDelete);
this.grpModify.Controls.Add(this.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.Controls.Add(this.txtSex);
this.grpData.Controls.Add(this.lblSex);
this.grpData.Controls.Add(this.txtDesignation);
this.grpData.Controls.Add(this.lblDesignation);
this.grpData.Controls.Add(this.lblEmplId);
this.grpData.Controls.Add(this.txtEmpName);
this.grpData.Controls.Add(this.txtEmpID);
this.grpData.Controls.Add(this.lblEmpName);
this.grpData.Location = new System.Drawing.Point(8, 8);
this.grpData.Name = "grpData";
this.grpData.Size = new System.Drawing.Size(208, 176);
this.grpData.TabIndex = 9;
this.grpData.TabStop = false;
this.grpData.Text = "Data";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table",
"Employee", new System.Data.Common.DataColumnMapping[] {
new
System.Data.Common.DataColumnMapping("Employee", "Employee"),
new
System.Data.Common.DataColumnMapping("EmpId", "EmpId"),
new
System.Data.Common.DataColumnMapping("Sex", "Sex"),
new
System.Data.Common.DataColumnMapping("Designation", "Designation")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = @"DELETE FROM Employee WHERE (EmpId
= @Original_EmpId) AND (Designation = @Original_Designation OR
@Original_Designation IS NULL AND Designation IS NULL) AND (Employee =
@Original_Employee OR @Original_Employee IS NULL AND Employee IS NULL) AND
(Sex = @Original_Sex OR @Original_Sex IS NULL AND Sex IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_EmpId",
System.Data.SqlDbType.Decimal, 9, System.Data.ParameterDirection.Input,
false, ((System.Byte)(18)), ((System.Byte)(0)), "EmpId",
System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_Designation",
System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Designation",
System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_Employee",
System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Employee",
System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_Sex",
System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Sex",
System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation
id=\"B3-AVON-HF04\";packet size=4096;user id=sa;data source=\".\";persist" +
" security info=False;initial catalog=Gokul";
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO Employee(Employee,
EmpId, Sex, Designation) VALUES (@Employee, @EmpId" +
", @Sex, @Designation); SELECT Employee, EmpId, Sex, Designation FROM
Employee WH" +
"ERE (EmpId = @EmpId)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Employee",
System.Data.SqlDbType.VarChar, 50, "Employee"));
this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@EmpId", System.Data.SqlDbType.Decimal,
9, System.Data.ParameterDirection.Input, false, ((System.Byte)(18)),
((System.Byte)(0)), "EmpId", System.Data.DataRowVersion.Current, null));
this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Sex", System.Data.SqlDbType.VarChar, 10,
"Sex"));
this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Designation",
System.Data.SqlDbType.VarChar, 50, "Designation"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT Employee, EmpId, Sex,
Designation FROM Employee";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE Employee SET Employee =
@Employee, EmpId = @EmpId, Sex = @Sex, Designation = @Designation WHERE
(EmpId = @Original_EmpId) AND (Designation = @Original_Designation OR
@Original_Designation IS NULL AND Designation IS NULL) AND (Employee =
@Original_Employee OR @Original_Employee 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.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Employee",
System.Data.SqlDbType.VarChar, 50, "Employee"));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@EmpId", System.Data.SqlDbType.Decimal,
9, System.Data.ParameterDirection.Input, false, ((System.Byte)(18)),
((System.Byte)(0)), "EmpId", System.Data.DataRowVersion.Current, null));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Sex", System.Data.SqlDbType.VarChar, 10,
"Sex"));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Designation",
System.Data.SqlDbType.VarChar, 50, "Designation"));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_EmpId",
System.Data.SqlDbType.Decimal, 9, System.Data.ParameterDirection.Input,
false, ((System.Byte)(18)), ((System.Byte)(0)), "EmpId",
System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_Designation",
System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Designation",
System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_Employee",
System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Employee",
System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_Sex",
System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Sex",
System.Data.DataRowVersion.Original, null));
//
// frmMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(432, 190);
this.Controls.Add(this.grpData);
this.Controls.Add(this.grpModify);
this.Controls.Add(this.grpSeek);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "frmMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Simple Data Binding";
this.Load += new System.EventHandler(this.frmMain_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
this.grpSeek.ResumeLayout(false);
this.grpModify.ResumeLayout(false);
this.grpData.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

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

private void frmMain_Load(object sender, System.EventArgs e)
{
try
{

sqlDataAdapter1.Fill ( dataSet11,"Employee" ) ;

}

catch ( Exception Ex )
{

MessageBox.Show ( Ex.Message ) ;
}

}

private void btnNext_Click(object sender, System.EventArgs e)
{
try
{

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

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

else

MessageBox.Show ( "EOF reached" ) ;

}

catch ( Exception Ex )
{

MessageBox.Show ( Ex.Message ) ;
}

return ;


}

private void btnPrevious_Click(object sender, System.EventArgs e)
{

try
{

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

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

else

MessageBox.Show ( "EOB reached" ) ;

}

catch ( Exception Ex )
{

MessageBox.Show ( Ex.Message ) ;
}

return ;

}

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

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

}

catch ( Exception Ex )
{

MessageBox.Show ( Ex.Message ) ;
}

return ;
}

private void btnLast_Click(object sender, System.EventArgs e)
{
try
{

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

}

catch ( Exception Ex )
{

MessageBox.Show ( Ex.Message ) ;
}

return ;
}

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

try
{

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

}

catch ( Exception Ex )
{

MessageBox.Show ( Ex.Message ) ;
}

return ;

}

}
}
 
M

Marc Vangrieken

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/library/system.data.dataset.acceptchanges.aspx

Kind regards,


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.Collections;
using System.ComponentModel;
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.SqlClient.SqlDataAdapter sqlDataAdapter1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private ADO.NET.DataSet1 dataSet11;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

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

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
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 InitializeComponent()
{
this.lblEmpName = new System.Windows.Forms.Label();
this.lblEmplId = new System.Windows.Forms.Label();
this.lblDesignation = new System.Windows.Forms.Label();
this.lblSex = new System.Windows.Forms.Label();
this.txtEmpName = new System.Windows.Forms.TextBox();
this.dataSet11 = new ADO.NET.DataSet1();
this.txtEmpID = new System.Windows.Forms.TextBox();
this.txtDesignation = new System.Windows.Forms.TextBox();
this.txtSex = new System.Windows.Forms.TextBox();
this.btnPrevious = 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.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.grpSeek.SuspendLayout();
this.grpModify.SuspendLayout();
this.grpData.SuspendLayout();
this.SuspendLayout();
//
// 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.lblDesignation.AutoSize = true;
this.lblDesignation.Location = new System.Drawing.Point(8, 104);
this.lblDesignation.Name = "lblDesignation";
this.lblDesignation.Size = new System.Drawing.Size(64, 16);
this.lblDesignation.TabIndex = 0;
this.lblDesignation.Text = "Designation";
//
// lblSex
//
this.lblSex.AutoSize = true;
this.lblSex.Location = new System.Drawing.Point(8, 144);
this.lblSex.Name = "lblSex";
this.lblSex.Size = new System.Drawing.Size(24, 16);
this.lblSex.TabIndex = 0;
this.lblSex.Text = "Sex";
//
// txtEmpName
//
this.txtEmpName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtEmpName.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.dataSet11, "Employee.Employee"));
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.Globalization.CultureInfo("en-US");
//
// txtEmpID
//
this.txtEmpID.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtEmpID.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.dataSet11, "Employee.EmpId"));
this.txtEmpID.Location = new System.Drawing.Point(104, 64);
this.txtEmpID.Name = "txtEmpID";
this.txtEmpID.Size = new System.Drawing.Size(96, 20);
this.txtEmpID.TabIndex = 1;
this.txtEmpID.Text = "";
//
// txtDesignation
//
this.txtDesignation.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.txtDesignation.DataBindings.Add(new
System.Windows.Forms.Binding("Text", this.dataSet11, "Employee.Designation"));
this.txtDesignation.Location = new System.Drawing.Point(104, 104);
this.txtDesignation.Name = "txtDesignation";
this.txtDesignation.Size = new System.Drawing.Size(96, 20);
this.txtDesignation.TabIndex = 1;
this.txtDesignation.Text = "";
//
// txtSex
//
this.txtSex.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtSex.DataBindings.Add(new System.Windows.Forms.Binding("Text",
this.dataSet11, "Employee.Sex"));
this.txtSex.Location = new System.Drawing.Point(104, 144);
this.txtSex.Name = "txtSex";
this.txtSex.Size = new System.Drawing.Size(96, 20);
this.txtSex.TabIndex = 1;
this.txtSex.Text = "";
//
// btnPrevious
//
this.btnPrevious.Location = new System.Drawing.Point(56, 24);
this.btnPrevious.Name = "btnPrevious";
this.btnPrevious.Size = new System.Drawing.Size(32, 23);
this.btnPrevious.TabIndex = 2;
this.btnPrevious.Text = "<";
this.btnPrevious.Click += new System.EventHandler(this.btnPrevious_Click);
//
// btnNext
//
this.btnNext.Location = new System.Drawing.Point(112, 24);
this.btnNext.Name = "btnNext";
this.btnNext.Size = new System.Drawing.Size(32, 23);
this.btnNext.TabIndex = 3;
this.btnNext.Text = ">";
this.btnNext.Click += new System.EventHandler(this.btnNext_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.EventHandler(this.btnUpdate_Click);
//
// grpSeek
//
this.grpSeek.Controls.Add(this.btnFirst);
this.grpSeek.Controls.Add(this.btnLast);
this.grpSeek.Controls.Add(this.btnNext);
this.grpSeek.Controls.Add(this.btnPrevious);
this.grpSeek.Location = new System.Drawing.Point(224, 8);
this.grpSeek.Name = "grpSeek";
this.grpSeek.Size = new System.Drawing.Size(200, 72);
this.grpSeek.TabIndex = 7;
this.grpSeek.TabStop = false;
this.grpSeek.Text = "Seek";
//
// btnFirst
//
this.btnFirst.Location = new System.Drawing.Point(8, 24);
this.btnFirst.Name = "btnFirst";
this.btnFirst.Size = new System.Drawing.Size(32, 23);
this.btnFirst.TabIndex = 5;
this.btnFirst.Text = "|<<";
this.btnFirst.Click += new System.EventHandler(this.btnFirst_Click);
//
// btnLast
//
this.btnLast.Location = new System.Drawing.Point(160, 24);
this.btnLast.Name = "btnLast";
this.btnLast.Size = new System.Drawing.Size(32, 23);
this.btnLast.TabIndex = 4;
this.btnLast.Text = ">>|";
this.btnLast.Click += new System.EventHandler(this.btnLast_Click);
//
// grpModify
//
this.grpModify.Controls.Add(this.btnUpdate);
this.grpModify.Controls.Add(this.btnDelete);
this.grpModify.Controls.Add(this.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.Controls.Add(this.txtSex);
this.grpData.Controls.Add(this.lblSex);
this.grpData.Controls.Add(this.txtDesignation);
this.grpData.Controls.Add(this.lblDesignation);
this.grpData.Controls.Add(this.lblEmplId);
this.grpData.Controls.Add(this.txtEmpName);
this.grpData.Controls.Add(this.txtEmpID);
this.grpData.Controls.Add(this.lblEmpName);
this.grpData.Location = new System.Drawing.Point(8, 8);
this.grpData.Name = "grpData";
this.grpData.Size = new System.Drawing.Size(208, 176);
this.grpData.TabIndex = 9;
this.grpData.TabStop = false;
this.grpData.Text = "Data";
//
// sqlDataAdapter1
//
this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
this.sqlDataAdapter1.TableMappings.AddRange(new
System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table",
"Employee", new System.Data.Common.DataColumnMapping[] {
new
System.Data.Common.DataColumnMapping("Employee", "Employee"),
new
System.Data.Common.DataColumnMapping("EmpId", "EmpId"),
new
System.Data.Common.DataColumnMapping("Sex", "Sex"),
new
System.Data.Common.DataColumnMapping("Designation", "Designation")})});
this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = @"DELETE FROM Employee WHERE (EmpId
= @Original_EmpId) AND (Designation = @Original_Designation OR
@Original_Designation IS NULL AND Designation IS NULL) AND (Employee =
@Original_Employee OR @Original_Employee IS NULL AND Employee IS NULL) AND
(Sex = @Original_Sex OR @Original_Sex IS NULL AND Sex IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConnection1;
this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_EmpId",
System.Data.SqlDbType.Decimal, 9, System.Data.ParameterDirection.Input,
false, ((System.Byte)(18)), ((System.Byte)(0)), "EmpId",
System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_Designation",
System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Designation",
System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_Employee",
System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Employee",
System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_Sex",
System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Sex",
System.Data.DataRowVersion.Original, null));
//
// sqlConnection1
//
this.sqlConnection1.ConnectionString = "workstation
id=\"B3-AVON-HF04\";packet size=4096;user id=sa;data source=\".\";persist" +
" security info=False;initial catalog=Gokul";
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = "INSERT INTO Employee(Employee,
EmpId, Sex, Designation) VALUES (@Employee, @EmpId" +
", @Sex, @Designation); SELECT Employee, EmpId, Sex, Designation FROM
Employee WH" +
"ERE (EmpId = @EmpId)";
this.sqlInsertCommand1.Connection = this.sqlConnection1;
this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Employee",
System.Data.SqlDbType.VarChar, 50, "Employee"));
this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@EmpId", System.Data.SqlDbType.Decimal,
9, System.Data.ParameterDirection.Input, false, ((System.Byte)(18)),
((System.Byte)(0)), "EmpId", System.Data.DataRowVersion.Current, null));
this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Sex", System.Data.SqlDbType.VarChar, 10,
"Sex"));
this.sqlInsertCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Designation",
System.Data.SqlDbType.VarChar, 50, "Designation"));
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT Employee, EmpId, Sex,
Designation FROM Employee";
this.sqlSelectCommand1.Connection = this.sqlConnection1;
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE Employee SET Employee =
@Employee, EmpId = @EmpId, Sex = @Sex, Designation = @Designation WHERE
(EmpId = @Original_EmpId) AND (Designation = @Original_Designation OR
@Original_Designation IS NULL AND Designation IS NULL) AND (Employee =
@Original_Employee OR @Original_Employee 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.sqlUpdateCommand1.Connection = this.sqlConnection1;
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Employee",
System.Data.SqlDbType.VarChar, 50, "Employee"));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@EmpId", System.Data.SqlDbType.Decimal,
9, System.Data.ParameterDirection.Input, false, ((System.Byte)(18)),
((System.Byte)(0)), "EmpId", System.Data.DataRowVersion.Current, null));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Sex", System.Data.SqlDbType.VarChar, 10,
"Sex"));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Designation",
System.Data.SqlDbType.VarChar, 50, "Designation"));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_EmpId",
System.Data.SqlDbType.Decimal, 9, System.Data.ParameterDirection.Input,
false, ((System.Byte)(18)), ((System.Byte)(0)), "EmpId",
System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_Designation",
System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Designation",
System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_Employee",
System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Employee",
System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new
System.Data.SqlClient.SqlParameter("@Original_Sex",
System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input,
false, ((System.Byte)(0)), ((System.Byte)(0)), "Sex",
System.Data.DataRowVersion.Original, null));
//
// frmMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(432, 190);
this.Controls.Add(this.grpData);
this.Controls.Add(this.grpModify);
this.Controls.Add(this.grpSeek);
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "frmMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Simple Data Binding";
this.Load += new System.EventHandler(this.frmMain_Load);
((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
this.grpSeek.ResumeLayout(false);
this.grpModify.ResumeLayout(false);
this.grpData.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

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

private void frmMain_Load(object sender, System.EventArgs e)
{
try
{

sqlDataAdapter1.Fill ( dataSet11,"Employee" ) ;

}

catch ( Exception Ex )
{

MessageBox.Show ( Ex.Message ) ;
}

}

private void btnNext_Click(object sender, System.EventArgs e)
{
try
{

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

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

else

MessageBox.Show ( "EOF reached" ) ;

}

catch ( Exception Ex )
{

MessageBox.Show ( Ex.Message ) ;
}

return ;

}

private void btnPrevious_Click(object sender, System.EventArgs e)
{

try
{

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

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

else

MessageBox.Show ( "EOB reached" ) ;

}

catch ( Exception Ex )
{

MessageBox.Show ( Ex.Message ) ;
}

return ;

}

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

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

}

catch ( Exception Ex )
{

MessageBox.Show ( Ex.Message ) ;
}

return ;
}

private void btnLast_Click(object sender, System.EventArgs e)
{
try
{

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

}

catch ( Exception Ex )
{

MessageBox.Show ( Ex.Message ) ;
}

return ;
}

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

try
{

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

}

catch ( Exception Ex )
{

MessageBox.Show ( Ex.Message ) ;
}

return ;

}

}

}
 
G

Guest

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!!!!
 
M

Marc Vangrieken

Hi,

I've been struggeling with this myself once, i now remeber that you
don't have to call AcceptChanges at all. Indeed it gets called
automatically after the update (Don't call it before updating like I
suggested because this will have the averse effect).
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!!!!

Where is your database? Is it an .MDF file that's in you Visual Studio
Project ? If that's the case, check if VS isn't copying it to the
output directory every time you run the application. See
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=427451&SiteID=1.
This was the cause of the "problem" i had a while ago.

Kind regards,
 
G

Guest

Thanks Marc. But still I am not able to update!
Database is SQL Server 7.0. Its under C:\MSSQL7\Data. No I tried everything
but still it is not updating.
 
R

RobinS

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.
---------------------------------------------------------
 
G

Guest

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.Tables[0].Rows[0][0].ToString() it
gives me the updated text!!!!

Can anyone please tell me what could be the problem
 
R

RobinS

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/library/ms246989(VS.80).aspx

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

Gokul said:
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.Tables[0].Rows[0][0].ToString() it
gives me the updated text!!!!

Can anyone please tell me what could be the problem

RobinS said:
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.
 
G

Guest

Robin I use SQL 2000 and adapter will create a connection for me.

RobinS said:
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/library/ms246989(VS.80).aspx

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

Gokul said:
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.Tables[0].Rows[0][0].ToString() it
gives me the updated text!!!!

Can anyone please tell me what could be the problem

RobinS said:
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.
---------------------------------------------------------

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!!!!

:

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/library/system.data.dataset.acceptchanges.aspx

Kind regards,


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.Collections;
using System.ComponentModel;
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.SqlClient.SqlDataAdapter
sqlDataAdapter1;
private System.Data.SqlClient.SqlCommand
sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand
sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand
sqlUpdateCommand1;
private System.Data.SqlClient.SqlCommand
sqlDeleteCommand1;
private System.Data.SqlClient.SqlConnection
sqlConnection1;
private ADO.NET.DataSet1 dataSet11;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components
= null;

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

//
// TODO: Add any constructor code after
InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
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 InitializeComponent()
{
this.lblEmpName = new
System.Windows.Forms.Label();
this.lblEmplId = new
System.Windows.Forms.Label();
this.lblDesignation = new
System.Windows.Forms.Label();
this.lblSex = new
System.Windows.Forms.Label();
this.txtEmpName = new
System.Windows.Forms.TextBox();
this.dataSet11 = new ADO.NET.DataSet1();
this.txtEmpID = new
System.Windows.Forms.TextBox();
this.txtDesignation = new
System.Windows.Forms.TextBox();
this.txtSex = new
System.Windows.Forms.TextBox();
this.btnPrevious = 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.sqlDataAdapter1 = new
System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new
System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new
System.Data.SqlClient.SqlConnection();
this.sqlInsertCommand1 = new
System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new
System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new
System.Data.SqlClient.SqlCommand();

((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.grpSeek.SuspendLayout();
this.grpModify.SuspendLayout();
this.grpData.SuspendLayout();
this.SuspendLayout();
//
// 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.lblDesignation.AutoSize = true;
this.lblDesignation.Location = new
System.Drawing.Point(8, 104);
this.lblDesignation.Name =
"lblDesignation";
this.lblDesignation.Size = new
System.Drawing.Size(64, 16);
this.lblDesignation.TabIndex = 0;
this.lblDesignation.Text = "Designation";
//
// lblSex
//
this.lblSex.AutoSize = true;
this.lblSex.Location = new
System.Drawing.Point(8, 144);
this.lblSex.Name = "lblSex";
this.lblSex.Size = new
System.Drawing.Size(24, 16);
this.lblSex.TabIndex = 0;
this.lblSex.Text = "Sex";
//
// txtEmpName
//
this.txtEmpName.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.txtEmpName.DataBindings.Add(new
System.Windows.Forms.Binding("Text",
this.dataSet11, "Employee.Employee"));
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.Globalization.CultureInfo("en-US");
//
// txtEmpID
//
this.txtEmpID.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.txtEmpID.DataBindings.Add(new
System.Windows.Forms.Binding("Text",
this.dataSet11, "Employee.EmpId"));
this.txtEmpID.Location = new
System.Drawing.Point(104, 64);
this.txtEmpID.Name = "txtEmpID";
this.txtEmpID.Size = new
System.Drawing.Size(96, 20);
 
R

RobinS

Did you create the Update, Insert, and Delete Command objects for your
adapter?

Robin S.
-------------------------------------------
Gokul said:
Robin I use SQL 2000 and adapter will create a connection for me.

RobinS said:
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/library/ms246989(VS.80).aspx

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

Gokul said:
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.Tables[0].Rows[0][0].ToString()
it
gives me the updated text!!!!

Can anyone please tell me what could be the problem

:

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.
---------------------------------------------------------

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!!!!

:

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/library/system.data.dataset.acceptchanges.aspx

Kind regards,


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.Collections;
using System.ComponentModel;
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.SqlClient.SqlDataAdapter
sqlDataAdapter1;
private System.Data.SqlClient.SqlCommand
sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand
sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand
sqlUpdateCommand1;
private System.Data.SqlClient.SqlCommand
sqlDeleteCommand1;
private System.Data.SqlClient.SqlConnection
sqlConnection1;
private ADO.NET.DataSet1 dataSet11;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container
components
= null;

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

//
// TODO: Add any constructor code after
InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool
disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
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 InitializeComponent()
{
this.lblEmpName = new
System.Windows.Forms.Label();
this.lblEmplId = new
System.Windows.Forms.Label();
this.lblDesignation = new
System.Windows.Forms.Label();
this.lblSex = new
System.Windows.Forms.Label();
this.txtEmpName = new
System.Windows.Forms.TextBox();
this.dataSet11 = new ADO.NET.DataSet1();
this.txtEmpID = new
System.Windows.Forms.TextBox();
this.txtDesignation = new
System.Windows.Forms.TextBox();
this.txtSex = new
System.Windows.Forms.TextBox();
this.btnPrevious = 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.sqlDataAdapter1 = new
System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new
System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new
System.Data.SqlClient.SqlConnection();
this.sqlInsertCommand1 = new
System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new
System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new
System.Data.SqlClient.SqlCommand();

((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.grpSeek.SuspendLayout();
this.grpModify.SuspendLayout();
this.grpData.SuspendLayout();
this.SuspendLayout();
//
// 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.lblDesignation.AutoSize = true;
this.lblDesignation.Location = new
System.Drawing.Point(8, 104);
this.lblDesignation.Name =
"lblDesignation";
this.lblDesignation.Size = new
System.Drawing.Size(64, 16);
this.lblDesignation.TabIndex = 0;
this.lblDesignation.Text =
"Designation";
//
// lblSex
//
this.lblSex.AutoSize = true;
this.lblSex.Location = new
System.Drawing.Point(8, 144);
this.lblSex.Name = "lblSex";
this.lblSex.Size = new
System.Drawing.Size(24, 16);
this.lblSex.TabIndex = 0;
this.lblSex.Text = "Sex";
//
// txtEmpName
//
this.txtEmpName.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.txtEmpName.DataBindings.Add(new
System.Windows.Forms.Binding("Text",
this.dataSet11, "Employee.Employee"));
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.Globalization.CultureInfo("en-US");
//
// txtEmpID
//
this.txtEmpID.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.txtEmpID.DataBindings.Add(new
System.Windows.Forms.Binding("Text",
this.dataSet11, "Employee.EmpId"));
this.txtEmpID.Location = new
System.Drawing.Point(104, 64);
this.txtEmpID.Name = "txtEmpID";
this.txtEmpID.Size = new
System.Drawing.Size(96, 20);
 
G

Guest

Adapter created all those command automatically! I didnt create them

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

Robin S.
-------------------------------------------
Gokul said:
Robin I use SQL 2000 and adapter will create a connection for me.

RobinS said:
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/library/ms246989(VS.80).aspx

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

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.Tables[0].Rows[0][0].ToString()
it
gives me the updated text!!!!

Can anyone please tell me what could be the problem

:

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.
---------------------------------------------------------

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!!!!

:

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/library/system.data.dataset.acceptchanges.aspx

Kind regards,


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.Collections;
using System.ComponentModel;
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.SqlClient.SqlDataAdapter
sqlDataAdapter1;
private System.Data.SqlClient.SqlCommand
sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand
sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand
sqlUpdateCommand1;
private System.Data.SqlClient.SqlCommand
sqlDeleteCommand1;
private System.Data.SqlClient.SqlConnection
sqlConnection1;
private ADO.NET.DataSet1 dataSet11;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container
components
= null;

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

//
// TODO: Add any constructor code after
InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool
disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
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 InitializeComponent()
{
this.lblEmpName = new
System.Windows.Forms.Label();
this.lblEmplId = new
System.Windows.Forms.Label();
this.lblDesignation = new
System.Windows.Forms.Label();
this.lblSex = new
System.Windows.Forms.Label();
this.txtEmpName = new
System.Windows.Forms.TextBox();
this.dataSet11 = new ADO.NET.DataSet1();
this.txtEmpID = new
System.Windows.Forms.TextBox();
this.txtDesignation = new
System.Windows.Forms.TextBox();
this.txtSex = new
System.Windows.Forms.TextBox();
this.btnPrevious = 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.sqlDataAdapter1 = new
System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new
System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new
System.Data.SqlClient.SqlConnection();
this.sqlInsertCommand1 = new
System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new
System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new
System.Data.SqlClient.SqlCommand();

((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.grpSeek.SuspendLayout();
this.grpModify.SuspendLayout();
this.grpData.SuspendLayout();
this.SuspendLayout();
//
// 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.lblDesignation.AutoSize = true;
this.lblDesignation.Location = new
System.Drawing.Point(8, 104);
this.lblDesignation.Name =
"lblDesignation";
this.lblDesignation.Size = new
System.Drawing.Size(64, 16);
this.lblDesignation.TabIndex = 0;
this.lblDesignation.Text =
"Designation";
//
// lblSex
//
this.lblSex.AutoSize = true;
this.lblSex.Location = new
System.Drawing.Point(8, 144);
this.lblSex.Name = "lblSex";
this.lblSex.Size = new
System.Drawing.Size(24, 16);
this.lblSex.TabIndex = 0;
this.lblSex.Text = "Sex";
//
// txtEmpName
//
this.txtEmpName.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.txtEmpName.DataBindings.Add(new
System.Windows.Forms.Binding("Text",
this.dataSet11, "Employee.Employee"));
 
R

RobinS

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 said:
Adapter created all those command automatically! I didnt create them

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

Robin S.
-------------------------------------------
Gokul said:
Robin I use SQL 2000 and adapter will create a connection for me.

:

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/library/ms246989(VS.80).aspx

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

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.Tables[0].Rows[0][0].ToString()
it
gives me the updated text!!!!

Can anyone please tell me what could be the problem

:

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.
---------------------------------------------------------

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!!!!

:

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/library/system.data.dataset.acceptchanges.aspx

Kind regards,


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.Collections;
using System.ComponentModel;
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.SqlClient.SqlDataAdapter
sqlDataAdapter1;
private System.Data.SqlClient.SqlCommand
sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand
sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand
sqlUpdateCommand1;
private System.Data.SqlClient.SqlCommand
sqlDeleteCommand1;
private System.Data.SqlClient.SqlConnection
sqlConnection1;
private ADO.NET.DataSet1 dataSet11;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container
components
= null;

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

//
// TODO: Add any constructor code
after
InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool
disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
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 InitializeComponent()
{
this.lblEmpName = new
System.Windows.Forms.Label();
this.lblEmplId = new
System.Windows.Forms.Label();
this.lblDesignation = new
System.Windows.Forms.Label();
this.lblSex = new
System.Windows.Forms.Label();
this.txtEmpName = new
System.Windows.Forms.TextBox();
this.dataSet11 = new
ADO.NET.DataSet1();
this.txtEmpID = new
System.Windows.Forms.TextBox();
this.txtDesignation = new
System.Windows.Forms.TextBox();
this.txtSex = new
System.Windows.Forms.TextBox();
this.btnPrevious = 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.sqlDataAdapter1 = new
System.Data.SqlClient.SqlDataAdapter();
this.sqlDeleteCommand1 = new
System.Data.SqlClient.SqlCommand();
this.sqlConnection1 = new
System.Data.SqlClient.SqlConnection();
this.sqlInsertCommand1 = new
System.Data.SqlClient.SqlCommand();
this.sqlSelectCommand1 = new
System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new
System.Data.SqlClient.SqlCommand();

((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
this.grpSeek.SuspendLayout();
this.grpModify.SuspendLayout();
this.grpData.SuspendLayout();
this.SuspendLayout();
//
// 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.lblDesignation.AutoSize = true;
this.lblDesignation.Location = new
System.Drawing.Point(8, 104);
this.lblDesignation.Name =
"lblDesignation";
this.lblDesignation.Size = new
System.Drawing.Size(64, 16);
this.lblDesignation.TabIndex = 0;
this.lblDesignation.Text =
"Designation";
//
// lblSex
//
this.lblSex.AutoSize = true;
this.lblSex.Location = new
System.Drawing.Point(8, 144);
this.lblSex.Name = "lblSex";
this.lblSex.Size = new
System.Drawing.Size(24, 16);
this.lblSex.TabIndex = 0;
this.lblSex.Text = "Sex";
//
// txtEmpName
//
this.txtEmpName.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.txtEmpName.DataBindings.Add(new
System.Windows.Forms.Binding("Text",
this.dataSet11, "Employee.Employee"));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top