检索到的数据无法在texbox中编辑 [英] Retrieved data cannot edit in texboxes

查看:40
本文介绍了检索到的数据无法在texbox中编辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

我想将数据从Mysql DB检索到文本框并对其进行编辑,然后再次保存到DB.首先,我成功检索了数据.但现在我无法对其进行编辑.可能是什么原因.
这是代码:


Dear Friends,

I want to retrieve data from the Mysql DB to textboxes and edit them and save to DB again. first I successfully retrieved data. but now I cannot edit them. what could be the reason.

here are the code :


namespace Comaco
{
    public partial class Form1_Edit : Form
    {
        MySqlConnection con = new MySqlConnection(DBConnection.GetConnectionString("Comaco.Properties.Settings.MySQLConnectionString").ToString());

        private MySqlCommand com;
        private MySqlDataAdapter dataAdapter;
        private DataSet ds;
        private DataTable datatable;

        public Form1_Edit()
        {
            InitializeComponent();
            btnEdit.Enabled = false;

        }

        public void loadData()
        {
            com = new MySqlCommand();
            String cmdString = "Select * from container where ContainerNo like ('" + txtContNo.Text + "%') ";
            dataAdapter = new MySqlDataAdapter(cmdString, con);
            ds = new DataSet();

            dataAdapter.Fill(ds, "container");

            datatable = ds.Tables["Container"];

        }

        private void FIllcontrolls()
        {

            txtContNo.Text = datatable.Rows[0]["ContainerNo"].ToString();
            txtUsed.Text = datatable.Rows[0]["GKId"].ToString();
            txtVesselRef.Text = datatable.Rows[0]["VesselRef"].ToString();
            txtLineOpt.Text = datatable.Rows[0]["LineOpt"].ToString();
            txtSetTemp.Text = datatable.Rows[0]["SetTemp"].ToString();
            txtPlugOnDate.Text = datatable.Rows[0]["PlugOnDate"].ToString();
            txtPlugOnTime.Text = (datatable.Rows[0]["PlugOnTime"]).ToString();
            txtLane.Text = (datatable.Rows[0]["Lane"]).ToString();
            txtVent.Text = (datatable.Rows[0]["Ventilation"]).ToString();
            txtRemarks.Text = (datatable.Rows[0]["Remarks"]).ToString();

            String cat = (datatable.Rows[0]["Category"]).ToString();

            switch (cat)
            {
                case "IMPORT" : cmbCategory.SelectedIndex=0; break;
                case "EXPORT": cmbCategory.SelectedIndex = 1; break;
                case "TRANSHIPMENT": cmbCategory.SelectedIndex = 2; break;
                case "RESTOW": cmbCategory.SelectedIndex = 3; break;
                case "OTHER": cmbCategory.SelectedIndex = 4; break;
                default: cmbCategory.SelectedIndex = 4; break;
            }

            txtVesselRef.ReadOnly = false;

        }

        private void txtContNo_Leave(object sender, EventArgs e)
        {
            if (txtContNo.Text != "")
            {
                loadData();
                FIllcontrolls();
                btnEdit.Enabled = true;

            }
            else
            {
                MessageBox.Show("Please Enter Container Number", "Warning");
                txtContNo.Focus();
            }

            txtContNo.Focus();
        }
    }
}


请给我一个快速的答案.

谢谢


please send me a quick answer.

thanks

推荐答案

首先在文本框中编辑数据,并为以下按钮选择保存按钮:-

在事件处理程序中

代码更新DataTable
喜欢


First of all edit data in textboxes and take a save button for eg:-

in the event handler

code to update the DataTable
like


datatable.Rows[0]["ContainerNo"]=containertxt.Text;


//then update the datasource..........

da.Update(ds,"container");




您可能会遇到错误,例如在不返回任何键列信息的select语句上无法动态生成更新命令的情况

在这里,您需要MySqlCommandBuilder(我希望以前没有使用MySql数据库)自动生成更新命令来更新数据库

希望这会有所帮助
祝你好运........




you may get error like dynamic generation of update command is not possible on select statement that does not return any key column info

Here you need MySqlCommandBuilder(I hope didn''t use MySql database before) to autmatically generate update command to update database

Hope this helps
Best of luck........


这篇关于检索到的数据无法在texbox中编辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆