Click here to Skip to main content
16,016,580 members

Comments by Thakur Varun Singh (Top 2 by date)

Thakur Varun Singh 18-May-13 3:57am View    
Ya Dave you are absolutely wright
Thakur Varun Singh 18-May-13 3:24am View    
Deleted
But i am using a primary key in the table and I want to know number of records updated in Repeater control. But it throwing ERROR : Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.

Below is the code and EMP_ID is the primary key in the table.

namespace Disconnected
{
public partial class CommandBuilder : System.Web.UI.Page
{
string constr = WebConfigurationManager.ConnectionStrings["ConnectDBString"].ConnectionString;
private SqlDataAdapter dad;
private DataTable dt;

void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(constr);

dad = new SqlDataAdapter("Select Emp_ID,FName from Employeed",con);


SqlCommandBuilder builder = new SqlCommandBuilder(dad);

dt = new DataTable();

dad.Fill(dt);

rptEmp.DataSource = dt;
rptEmp.DataBind();
}

protected void lnkUpdate_Click(object sender, EventArgs e)
{

for (int i = 0; i < rptEmp.Items.Count;i++)
{
RepeaterItem item = rptEmp.Items[i];

TextBox txtId = (TextBox)item.FindControl("txtId");
TextBox txtFname = (TextBox)item.FindControl("txtFname");

if (dt.Rows[i]["Emp_ID"] != txtId.Text)
dt.Rows[i]["Emp_ID"] = txtId.Text;

if (dt.Rows[i]["FNAME"] != txtFname.Text)
dt.Rows[i]["FNAME"] = txtFname.Text;

}

//set batch size to maximum size
dad.UpdateBatchSize = 0;



// perform update

int numbUpdated = dad.Update(dt);

lblResults.Text = String.Format("Updated {0} rows",numbUpdated);
}
}
}