Help me update product [modified]
-
public partial class admin_edit_sach : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
laysach();
}
}
private void laysach()
{
int masach = int.Parse(Request.QueryString["id"].ToString());
String StrCnn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("~/App_Data/QLBansach.mdb");
OleDbConnection cnn = new OleDbConnection(StrCnn);
cnn.Open();
OleDbCommand cmd = cnn.CreateCommand();
cmd.CommandText = "select * from Sach where MaCD=" + masach;
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
txtTenSach.Text = ds.Tables[0].Rows[0]["Tensach"].ToString();
DropChuDe.SelectedValue = ds.Tables[0].Rows[0]["MaCD"].ToString();
DropNXB.SelectedValue = ds.Tables[0].Rows[0]["MaNXB"].ToString();
txtDonGia.Text = ds.Tables[0].Rows[0]["Dongia"].ToString();
Calendar1.SelectedDate = ds.Tables[0].Rows[0]["Ngaycapnhat"].ToString;
FileUpload1.FileName = ds.Tables[0].Rows[0]["Hinhminhhoa"].ToString();
txtMoTa.Text = ds.Tables[0].Rows[0]["Mota"].ToString();
cnn.Close();
}
protected void Btupdate_Click(object sender, EventArgs e)
{
int masach = int.Parse(Request.QueryString["id"].ToString());
String StrCnn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("~/App_Data/QLBansach.mdb");
OleDbConnection cnn = new OleDbConnection(StrCnn);
cnn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = cnn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "UPDATE Sach SET Tensach='" + txtTenSach.Text + "','" + DropChuDe.SelectedValue + "','" + DropNXB.SelectedValue + "','" + txtDonGia.Text + "','" + Calendar1.SelectedDate.Day + "/" + Calendar1.SelectedDate.Month + "/" + Calendar1.SelectedDate.Year + "','" + FileUpload1.FileName + "','" + txtMoTa.Text + "' Where MaNXB=" + masach;
cmd.ExecuteNonQuery();
cnn.Close();
Response.Redirect("~/Admin/ds_sach.aspx");
}
}Erros
ompilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.Compiler Error Message: CS0428: Cannot convert
-
public partial class admin_edit_sach : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
laysach();
}
}
private void laysach()
{
int masach = int.Parse(Request.QueryString["id"].ToString());
String StrCnn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("~/App_Data/QLBansach.mdb");
OleDbConnection cnn = new OleDbConnection(StrCnn);
cnn.Open();
OleDbCommand cmd = cnn.CreateCommand();
cmd.CommandText = "select * from Sach where MaCD=" + masach;
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
txtTenSach.Text = ds.Tables[0].Rows[0]["Tensach"].ToString();
DropChuDe.SelectedValue = ds.Tables[0].Rows[0]["MaCD"].ToString();
DropNXB.SelectedValue = ds.Tables[0].Rows[0]["MaNXB"].ToString();
txtDonGia.Text = ds.Tables[0].Rows[0]["Dongia"].ToString();
Calendar1.SelectedDate = ds.Tables[0].Rows[0]["Ngaycapnhat"].ToString;
FileUpload1.FileName = ds.Tables[0].Rows[0]["Hinhminhhoa"].ToString();
txtMoTa.Text = ds.Tables[0].Rows[0]["Mota"].ToString();
cnn.Close();
}
protected void Btupdate_Click(object sender, EventArgs e)
{
int masach = int.Parse(Request.QueryString["id"].ToString());
String StrCnn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("~/App_Data/QLBansach.mdb");
OleDbConnection cnn = new OleDbConnection(StrCnn);
cnn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = cnn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "UPDATE Sach SET Tensach='" + txtTenSach.Text + "','" + DropChuDe.SelectedValue + "','" + DropNXB.SelectedValue + "','" + txtDonGia.Text + "','" + Calendar1.SelectedDate.Day + "/" + Calendar1.SelectedDate.Month + "/" + Calendar1.SelectedDate.Year + "','" + FileUpload1.FileName + "','" + txtMoTa.Text + "' Where MaNXB=" + masach;
cmd.ExecuteNonQuery();
cnn.Close();
Response.Redirect("~/Admin/ds_sach.aspx");
}
}Erros
ompilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.Compiler Error Message: CS0428: Cannot convert
Where is the parenthesis for this ??
Calendar1.SelectedDate = ds.Tables[0].Rows[0]["Ngaycapnhat"].ToString;
Should beCalendar1.SelectedDate = DateTime.Parse(ds.Tables[0].Rows[0]["Ngaycapnhat"].ToString());
The parenthesis for ToString is missing ... :) Cheers.Abhishek Sur **Don't forget to click "Good Answer" if you like this Solution.
My Latest Articles-->** Simplify Code Using NDepend
Basics of Bing Search API using .NET
Microsoft Bing MAP using Javascript -
public partial class admin_edit_sach : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
laysach();
}
}
private void laysach()
{
int masach = int.Parse(Request.QueryString["id"].ToString());
String StrCnn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("~/App_Data/QLBansach.mdb");
OleDbConnection cnn = new OleDbConnection(StrCnn);
cnn.Open();
OleDbCommand cmd = cnn.CreateCommand();
cmd.CommandText = "select * from Sach where MaCD=" + masach;
OleDbDataAdapter da = new OleDbDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
txtTenSach.Text = ds.Tables[0].Rows[0]["Tensach"].ToString();
DropChuDe.SelectedValue = ds.Tables[0].Rows[0]["MaCD"].ToString();
DropNXB.SelectedValue = ds.Tables[0].Rows[0]["MaNXB"].ToString();
txtDonGia.Text = ds.Tables[0].Rows[0]["Dongia"].ToString();
Calendar1.SelectedDate = ds.Tables[0].Rows[0]["Ngaycapnhat"].ToString;
FileUpload1.FileName = ds.Tables[0].Rows[0]["Hinhminhhoa"].ToString();
txtMoTa.Text = ds.Tables[0].Rows[0]["Mota"].ToString();
cnn.Close();
}
protected void Btupdate_Click(object sender, EventArgs e)
{
int masach = int.Parse(Request.QueryString["id"].ToString());
String StrCnn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("~/App_Data/QLBansach.mdb");
OleDbConnection cnn = new OleDbConnection(StrCnn);
cnn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = cnn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "UPDATE Sach SET Tensach='" + txtTenSach.Text + "','" + DropChuDe.SelectedValue + "','" + DropNXB.SelectedValue + "','" + txtDonGia.Text + "','" + Calendar1.SelectedDate.Day + "/" + Calendar1.SelectedDate.Month + "/" + Calendar1.SelectedDate.Year + "','" + FileUpload1.FileName + "','" + txtMoTa.Text + "' Where MaNXB=" + masach;
cmd.ExecuteNonQuery();
cnn.Close();
Response.Redirect("~/Admin/ds_sach.aspx");
}
}Erros
ompilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.Compiler Error Message: CS0428: Cannot convert
Try Calendar1.SelectedDate =DateTime.Parse(ds.Tables[0].Rows[0]["Ngaycapnhat"].ToString());