Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 18, 2012 04:47 AM by Decker Dong - MSFT
Member
258 Points
175 Posts
Feb 16, 2012 09:43 AM|LINK
bro i have Question about Updating Data in Database
In Update.aspx.cs i have update button
protected void UpdateButton_Click(object sender, EventArgs e) { EditButton.Visible = false; string UpStuName = ((TextBox)SSFormView.FindControl("TbStuName")).Text; string UpStuGender = ((DropDownList)SSFormView.FindControl("DlStuGender")).SelectedValue; string UpStudob = ((TextBox)SSFormView.FindControl("TbStudob")).Text; string UpStuLanguage = ((DropDownList)SSFormView.FindControl("DlStuLanguage")).SelectedValue; string UpStuBlood = ((DropDownList)SSFormView.FindControl("DlStuBlood")).SelectedValue; string UpStuDis = ((TextBox)SSFormView.FindControl("TbStuDis")).Text; string UpStuPhone = ((TextBox)SSFormView.FindControl("TbStuPhone")).Text; string UpStuMob = ((TextBox)SSFormView.FindControl("TbStuMob")).Text; string UpStuEmail = ((TextBox)SSFormView.FindControl("TbStuEmail")).Text; string UpStuAdd = ((TextBox)SSFormView.FindControl("TbStuAdd")).Text; string UpStuPic = ((TextBox)SSFormView.FindControl("TbStuPic")).Text; string id = ((Label)SSFormView.FindControl("LbStuId")).Text; DatabaseAccess.UpdateStuProfile(UpStuName, UpStuGender, UpStudob, UpStuLanguage, UpStuBlood, UpStuDis, UpStuPhone, UpStuMob, UpStuEmail, UpStuAdd, UpStuPic, id); }
Method in DataBaseAccess.cs page for updating data in data base
public static void UpdateStuProfile(string UpStuName, string UpStuGender, string UpStudob, string UpStuLanguage, string UpStuBlood, string UpStuDis, string UpStuPhone, string UpStuMob, string UpStuEmail, string UpStuAdd, string UpStuPic,string id) { string query = "Update [Student] set [Student_Name]=@Student_Name, [Student_Gender]=@Student_Gender, [Student_Dob]=@Student_Dob" + ", [Student_Language]=@Studetn_Language, [Student_Blood_Group]=@Student_Blood_Group, [Student_Disability]=@Student_Disability" + ", [Student_Phone]=@Student_Phone, [Student_Mobile]=@Student_Mobile, [Student_Email]=@Student_Email, [Student_Address]=@Student_Address" + ", [Student_Pic]=@Student_Pic WHERE [Student_Id] = @Student_Id"; SqlCommand cmd = DataBase.CreateCmnd(query); cmd.Parameters.AddWithValue("@Student_Name", UpStuName); cmd.Parameters.AddWithValue("@Student_Gender", UpStuGender); cmd.Parameters.AddWithValue("@Student_Dob", UpStudob); cmd.Parameters.AddWithValue("@Studetn_Language", UpStuLanguage); cmd.Parameters.AddWithValue("@Student_Blood_Group", UpStuBlood); cmd.Parameters.AddWithValue("@Student_Disability", UpStuDis); cmd.Parameters.AddWithValue("@Student_Phone", UpStuPhone); cmd.Parameters.AddWithValue("@Student_Mobile", UpStuMob); cmd.Parameters.AddWithValue("@Student_Email", UpStuEmail); cmd.Parameters.AddWithValue("@Student_Address", UpStuAdd); cmd.Parameters.AddWithValue("@Student_Pic", UpStuPic); cmd.Parameters.AddWithValue("@Student_Id", id); DataBase.ExecuteUpdateCmnd(cmd); }
so its my code it run with no error but it not updating my data base recode
plz help me
226 Points
95 Posts
Feb 16, 2012 09:51 AM|LINK
Hi,
Example: Update ALL the rows in the Product table. We increase the ListPrice by 5%. UPDATE Product SET ListPrice = ListPrice * 1.02 GO SELECT * FROM Product ORDER BY DESC ProductID GO
Also Visit on this link for more details: http://aspdotnetblogspot.blogspot.in/
Thanks,
All-Star
118619 Points
18779 Posts
Feb 18, 2012 04:47 AM|LINK
Unseendreamzzz DataBase.ExecuteUpdateCmnd(cmd);
Please change to cmd.ExecuteNonQuery()。
Unseendreamz...
Member
258 Points
175 Posts
update data in database
Feb 16, 2012 09:43 AM|LINK
bro i have Question about Updating Data in Database
In Update.aspx.cs i have update button
protected void UpdateButton_Click(object sender, EventArgs e)
{
EditButton.Visible = false;
string UpStuName = ((TextBox)SSFormView.FindControl("TbStuName")).Text;
string UpStuGender = ((DropDownList)SSFormView.FindControl("DlStuGender")).SelectedValue;
string UpStudob = ((TextBox)SSFormView.FindControl("TbStudob")).Text;
string UpStuLanguage = ((DropDownList)SSFormView.FindControl("DlStuLanguage")).SelectedValue;
string UpStuBlood = ((DropDownList)SSFormView.FindControl("DlStuBlood")).SelectedValue;
string UpStuDis = ((TextBox)SSFormView.FindControl("TbStuDis")).Text;
string UpStuPhone = ((TextBox)SSFormView.FindControl("TbStuPhone")).Text;
string UpStuMob = ((TextBox)SSFormView.FindControl("TbStuMob")).Text;
string UpStuEmail = ((TextBox)SSFormView.FindControl("TbStuEmail")).Text;
string UpStuAdd = ((TextBox)SSFormView.FindControl("TbStuAdd")).Text;
string UpStuPic = ((TextBox)SSFormView.FindControl("TbStuPic")).Text;
string id = ((Label)SSFormView.FindControl("LbStuId")).Text;
DatabaseAccess.UpdateStuProfile(UpStuName, UpStuGender, UpStudob, UpStuLanguage, UpStuBlood, UpStuDis, UpStuPhone, UpStuMob, UpStuEmail, UpStuAdd, UpStuPic, id);
}
Method in DataBaseAccess.cs page for updating data in data base
public static void UpdateStuProfile(string UpStuName, string UpStuGender, string UpStudob, string UpStuLanguage, string UpStuBlood, string UpStuDis, string UpStuPhone, string UpStuMob, string UpStuEmail, string UpStuAdd, string UpStuPic,string id)
{
string query = "Update [Student] set [Student_Name]=@Student_Name, [Student_Gender]=@Student_Gender, [Student_Dob]=@Student_Dob" +
", [Student_Language]=@Studetn_Language, [Student_Blood_Group]=@Student_Blood_Group, [Student_Disability]=@Student_Disability" +
", [Student_Phone]=@Student_Phone, [Student_Mobile]=@Student_Mobile, [Student_Email]=@Student_Email, [Student_Address]=@Student_Address" +
", [Student_Pic]=@Student_Pic WHERE [Student_Id] = @Student_Id";
SqlCommand cmd = DataBase.CreateCmnd(query);
cmd.Parameters.AddWithValue("@Student_Name", UpStuName);
cmd.Parameters.AddWithValue("@Student_Gender", UpStuGender);
cmd.Parameters.AddWithValue("@Student_Dob", UpStudob);
cmd.Parameters.AddWithValue("@Studetn_Language", UpStuLanguage);
cmd.Parameters.AddWithValue("@Student_Blood_Group", UpStuBlood);
cmd.Parameters.AddWithValue("@Student_Disability", UpStuDis);
cmd.Parameters.AddWithValue("@Student_Phone", UpStuPhone);
cmd.Parameters.AddWithValue("@Student_Mobile", UpStuMob);
cmd.Parameters.AddWithValue("@Student_Email", UpStuEmail);
cmd.Parameters.AddWithValue("@Student_Address", UpStuAdd);
cmd.Parameters.AddWithValue("@Student_Pic", UpStuPic);
cmd.Parameters.AddWithValue("@Student_Id", id);
DataBase.ExecuteUpdateCmnd(cmd);
}
so its my code it run with no error but it not updating my data base recode
plz help me
anildob84
Member
226 Points
95 Posts
Re: update data in database
Feb 16, 2012 09:51 AM|LINK
Hi,
Example: Update ALL the rows in the Product table. We increase the ListPrice by 5%.
UPDATE Product
SET ListPrice = ListPrice * 1.02
GO
SELECT * FROM Product ORDER BY DESC ProductID
GO
Also Visit on this link for more details: http://aspdotnetblogspot.blogspot.in/
Thanks,
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: update data in database
Feb 18, 2012 04:47 AM|LINK
Please change to cmd.ExecuteNonQuery()。