-
27-09-2011, 05:31 PM #1Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
lệnh update không báo lỗi nhưng không chép vào csdl
Mấy anh chị làm ơn xem dùm em dòng code này:
string chuoikn = "server=localhost;uid=;pwd=;database=webbandt; inte grated security=true";
SqlConnection c = new SqlConnection(chuoikn);
c.Open();
string chuoitruyvan;
SqlCommand m = new SqlCommand();
m.Connection = c;
if (txtSocm.Text == "")
{
chuoitruyvan = "update users set hoten='" + txtHo.Text + ",diachi='" + txtDc.Text + "',sodt='" + txtDt.Text + "',email='" + txtEmail.Text + "',socmnd='" + txtSocm.Text + "' where idUser=" + lblId.Text;
m.CommandText = chuoitruyvan;
m.ExecuteNonQuery();
Response.Write("<script>aler('Cập nhật thành công.Bạn có thể tiếp tục mua hàng')</script>");
}
else
{
chuoitruyvan = "update users set hoten='" + txtHo.Text + ",diachi='" + txtDc.Text + "',sodt='" + txtDt.Text + "',email='" + txtEmail.Text + "',socmnd='" + txtSocm.Text + "' where idUser="+lblId.Text;
m.CommandText = chuoitruyvan;
m.ExecuteNonQuery();
Response.Write("<script>aler('Cập nhật thành công.Bạn có thể tiếp tục mua hàng')</script>");
}
try
{
c.Close();
}
catch (Exception ex)
{
Response.Write("Thông Báo Lỗi:"+ex.Message);
}
c.Close();
View more random threads:
- Thắc mắc về Path và Server.MapPath
- làm sao cho giá trị rỗng đầu tiên trong dropdownlist khi đã kết nối với csdl
- lỗi "The state information is invalid for this page and might be corrupted." mặc dù chưa code
- Cách cài đặt VCalendar trong web asp.net?
- Không hiểu nguyên nhân lỗi not fond 404
- upload của google driver và skydriver viết bằng kỹ thuật gì?
- Crystal report bắt log on mỗi lần thay đổi
- code download cho imagebutton & ...
- Làm web đa ngôn ngữ (Việt - Anh) như thế nào với ASP.NET
- Không bật được chế độ desgin khi thiết kế web
-
27-09-2011, 05:36 PM #2Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Mình nghĩ vì điều kiện idUser="+lblId.Text; chưa xảy ra. bạn tạo một điểm ngắt test thử xem!
-
27-09-2011, 05:46 PM #3Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Là sao mình không hiểu.Bạn có thể chỉ rõ cho mình được không.Mình cám ơn
-
27-09-2011, 06:34 PM #4Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Đây là toàn bộ phần code của em .Nhớ anh xem dùm.Xin cám ơn.
Mã:protected void Page_Load(object sender, EventArgs e) { string chuoikn = "server=localhost;uid=;pwd=;database=webbandt;integrated security=true"; SqlConnection c = new SqlConnection(chuoikn); c.Open(); string chuoitruyvan = "select * from users where email='"+Session["email"]+"'"; SqlCommand m = new SqlCommand(); m.Connection = c; m.CommandText = chuoitruyvan; SqlDataReader d; d = m.ExecuteReader(); while (d.Read()) { lblId.Text = d["idUser"].ToString(); txtHo.Text = d["HoTen"].ToString(); txtDc.Text = d["DiaChi"].ToString(); txtDt.Text = d["SoDT"].ToString(); txtEmail.Text = d["Email"].ToString(); txtSocm.Text = d["SoCMND"].ToString(); } d.Close(); c.Close(); } protected void btnCn_Click(object sender, ImageClickEventArgs e) { string chuoikn = "server=localhost;uid=;pwd=;database=webbandt;integrated security=true"; SqlConnection c = new SqlConnection(chuoikn); c.Open(); string chuoitruyvan; SqlCommand m = new SqlCommand(); m.Connection = c; if (txtSocm.Text == "") { chuoitruyvan = "update users set hoten='" + txtHo.Text + "',diachi='" + txtDc.Text + "',sodt='" + txtDt.Text + "',email='" + txtEmail.Text + "' where idUser=" + lblId.Text; m.CommandText = chuoitruyvan; m.ExecuteNonQuery(); Response.Write("<script>aler('Cập nhật thành công.Bạn có thể tiếp tục mua hàng')</script>"); } else { chuoitruyvan = "update users set hoten='" + txtHo.Text + "',diachi='" + txtDc.Text + "',sodt='" + txtDt.Text + "',email='" + txtEmail.Text + "',socmnd='" + txtSocm.Text + "' where idUser="+lblId.Text; m.CommandText = chuoitruyvan; m.ExecuteNonQuery(); Response.Write("<script>aler('Cập nhật thành công.Bạn có thể tiếp tục mua hàng')</script>"); } try { c.Close(); } catch (Exception ex) { Response.Write("Thông Báo Lỗi:"+ex.Message); } c.Close(); }
-
28-09-2011, 12:13 PM #5Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Bạn thử để 1 con Bug ở đoạn click vào button xem sao. Rồi F11 tìm lỗi thôi.
Mấy cái này bạn phải tập làm thì mới rành được.
-
01-10-2011, 10:01 AM #6Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Trong Page_Load thêm dòng
if(!IPostback)
{
/// Fill dữ liệu
}
-
01-10-2011, 05:26 PM #7Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
tại nút cập nhật bạn dùng hàm "if" có ý nghĩa gì vậy, mình thấy nó hok có tác dụng gì hết.
-
02-10-2011, 06:47 PM #8Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Khi bạn click button Update thì nó sẽ potsback lên server. Vì vậy, nếu như ko có !IsPostBack thì nó sẽ chạy lại sự kiện Page_Load và fill lại dữ liệu cũ vào control trên page. Lúc này quá trình update là có nhưng là update dữ liệu cũ.
Thông qua phân tích dữ liệu Google từ 86 quốc gia, mới đây, một công ty tại Anh đã công bố bảng xếp hạng kích tấc "cậu nhỏ" của các nước trên thế giới. Kết quả, hầu hết các nước xếp ở nhóm đầu của...
"Chim" của chàng trai Việt thuộc...