wyl458619358 2017-05-31 07:33 采纳率: 0%
浏览 2805
已采纳

连接上了数据库,执行了insert动作,但是数据库没有插入的数据

脑袋疼,感觉就是执行了,没有commit。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Oracle.ManagedDataAccess.Client;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Oracle.ManagedDataAccess.Types;
using Oracle.ManagedDataAccess.Client.SqlGen;
using System.Windows.Forms;
using System.Data.OracleClient;

public partial class his_device : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{

    if (Panel1.Visible == true)
    {
        Button1.Text = "Show Search Panel";
        Panel1.Visible = false;
    }
    else
    {
        Button1.Text = "Hide Search Panel";
        Panel1.Visible = true;
    }
}
protected void btnSearch_Click(object sender, EventArgs e)
{
    //this.HISI_DEVICE.SelectCommand="SELECT * FROM SCC_B2B.HIS_DEVICE WHERE DEVICE_NAME LIKE '" + this.TxtDevice.Text + "%'";
    //this.GridView1.DataBind();

    using (Oracle.ManagedDataAccess.Client.OracleConnection conn = new Oracle.ManagedDataAccess.Client.OracleConnection())
    {
        conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

        string str_sql = "SELECT * FROM SCC_B2B.HIS_DEVICE";
        TxtDevice.Text.Replace("'", "");
        TxtDevice.Text.Replace(";", "");
        if (!TxtDevice.Text.Equals(""))
        {
            str_sql = str_sql + " WHERE DEVICE_NAME LIKE '" + TxtDevice.Text + "%'";
        }
        Oracle.ManagedDataAccess.Client.OracleDataAdapter da = new Oracle.ManagedDataAccess.Client.OracleDataAdapter(str_sql, conn);

        DataSet ds = new DataSet();

        da.Fill(ds, "Device");

        GridView1.DataSource = ds;
        GridView1.DataBind();
        da.Dispose();
        ds.Dispose();
    }
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{

}
protected void GridView1_PageIndexChanging(object sender, EventArgs e)
{

}
protected void Button2_Click(object sender, EventArgs e)
{
    Response.Redirect("../Default.aspx");
}


protected void btnInsert_Click1(object sender, EventArgs e)
{
    using (Oracle.ManagedDataAccess.Client.OracleConnection conn = new Oracle.ManagedDataAccess.Client.OracleConnection())
    {

        conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        Oracle.ManagedDataAccess.Client.OracleCommand cmd = new Oracle.ManagedDataAccess.Client.OracleCommand();
        conn.Open();
        string sql = ("insert into SCC_B2B.HIS_DEVICE (device_name,device_type) values( '"+TxtDevice.Text+"','"+TxtFactory.Text+"')");

        conn.Close();
        if (TxtDevice.Text == "")
        {
            MessageBox.Show("Device_name cannot be null", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        else
        {
            if (TxtFactory.Text == "")
            {
                Response.Write("Device_type cannot be null");
            }
            else
            {


                    Response.Write("数据添加成功!");


            }
        }
    }
}

protected void btnDelete_Click(object sender, EventArgs e)
{
    using (Oracle.ManagedDataAccess.Client.OracleConnection conn = new Oracle.ManagedDataAccess.Client.OracleConnection())
    {


        Oracle.ManagedDataAccess.Client.OracleCommand cmd = new Oracle.ManagedDataAccess.Client.OracleCommand();
        conn.Open();
        string sql = ("insert into SCC_B2B.HIS_DEVICE (device_name,device_type) values( '" + TxtDevice.Text + "','" + TxtFactory.Text + "')");
        int ret = (int)cmd.ExecuteNonQuery();
        conn.Close();
        if (TxtDevice.Text == "")
        {
            MessageBox.Show("Device_name cannot be null", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        else
        {
            if (TxtFactory.Text == "")
            {
                MessageBox.Show("Device_type cannot be null", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                if (ret > 0)
                {

                    MessageBox.Show("数据添加成功!");
                }
                else
                {
                    MessageBox.Show("数据添加失败!");
                }
            }
        }
    }
}

}

  • 写回答

2条回答 默认 最新

  • 冷咖啡15 2017-05-31 10:18
    关注

    上面数据库插入的代码 根本没有执行去数据库插入数据这个事务,只是把数据库打开 然后就关闭了 什么也没操作啊。cmd.executeXXXXX()方法根本没有!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料