TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
umair mohsin
1.4k
387
65.6k
record is not updating
Feb 13 2015 3:25 AM
Record is not updating when I click to update button. my database table has four columns id is set to primary key and other columns are first name last name and class
Here is my code for row updating event:
protected
void
GridView1_RowUpdating(
object
sender,
GridViewUpdateEventArgs
e)
{
cs=connection string in web.config file.
using
(
SqlConnection
conn =
new
SqlConnection
(cs))
{
SqlCommand
cmd =
new
SqlCommand
();
cmd.Connection = conn;
cmd.CommandText =
" update student_record set firstname=@firstname,lastname=@lastname,class=@class where id=@id"
;
cmd.CommandType =
CommandType
.Text;
string
id=GridView1.Rows[e.RowIndex ].Cells [2].Text ;
string
fname=((
TextBox
)GridView1.Rows[e.RowIndex ].FindControl(
"TextBox1"
)).Text ;
string
lname=((
TextBox
)GridView1.Rows [e.RowIndex ].FindControl(
"TextBox2"
)).Text ;
string
clas = ((
TextBox
)GridView1.Rows[e.RowIndex].FindControl(
"TextBox3"
)).Text;
conn.Open();
cmd.Parameters.AddWithValue(
"@id"
,id);
cmd.Parameters.AddWithValue(
"@firstname"
, fname);
cmd.Parameters.AddWithValue(
"@lastname"
, lname );
cmd.Parameters.AddWithValue(
"@class"
, clas);
cmd.ExecuteNonQuery();
}
GridView1.EditIndex = -1;
binddata();
here is the bind data function coding
private
void
binddata()
{
SqlConnection
conn =
new
SqlConnection
(cs);
DataSet
ds =
new
DataSet
();
string
select =
"select * from student_record"
;
SqlDataAdapter
sda =
new
SqlDataAdapter
(select ,conn );
conn.Open();
sda.Fill(ds,
"mydbtable1"
);
GridView1.DataSource = ds;
GridView1.DataBind();
conn.Close();
}
source file is also attached.anyone help me in this.
Attachment:
demo gridview.rar
Reply
Answers (
9
)
External table is not in the expected format. ASP.net C#
c# method call when leaving asp.net textbox