16,016,580 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
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);
}
}
}