Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Help me update product [modified]

Help me update product [modified]

Scheduled Pinned Locked Moved ASP.NET
helpdesignsysadminannouncementlearning
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    trinhitc
    wrote on last edited by
    #1

    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

    A K 2 Replies Last reply
    0
    • T trinhitc

      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

      A Offline
      A Offline
      Abhishek Sur
      wrote on last edited by
      #2

      Where is the parenthesis for this ?? Calendar1.SelectedDate = ds.Tables[0].Rows[0]["Ngaycapnhat"].ToString; Should be Calendar1.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

      1 Reply Last reply
      0
      • T trinhitc

        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

        K Offline
        K Offline
        Krishhhhhhhhhhhhhh
        wrote on last edited by
        #3

        Try Calendar1.SelectedDate =DateTime.Parse(ds.Tables[0].Rows[0]["Ngaycapnhat"].ToString());

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups