- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Data.OracleClient;
- public partial class Updatecontract : System.Web.UI.Page
- {
- string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
- protected void Page_Load(object sender, EventArgs e)
- {
- OracleConnection connection = new OracleConnection(connectionString);
- string sqlstr = "select * from customer";
- OracleCommand cmd = new OracleCommand(sqlstr, connection);
- connection.Open();
- OracleDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- Ddl_customer.Items.Add(new ListItem(dr["custom_name"].ToString(),dr["custom_id"].ToString()));
- }
- connection.Close();
- sqlstr="select * from product";
- cmd.CommandText=sqlstr;
- cmd.Connection=connection;
- connection.Open();
- dr=cmd.ExecuteReader();
- while (dr.Read())
- {
- Ddl_product.Items.Add(new ListItem(dr["product_name"].ToString(),dr["product_id"].ToString()));
- }
- connection.Close();
- if (!IsPostBack)
- Display();
- }
- public void Display()
- {
- OracleConnection connection = new OracleConnection(connectionString);
- string sqlstr = "select * from contract,contract_detail where contract.contract_id=contract_detail.contract_id and contract.contract_id=:contract_id";
- OracleCommand cmd = new OracleCommand(sqlstr, connection);
- cmd.Parameters.Add("contract_id", OracleType.Char).Value = Request.QueryString["contract_id"];
- //DataTable dt = new DataTable();
- //OracleDataAdapter da = new OracleDataAdapter(cmd);
- //da.Fill(dt);
- //Lbl_contractid.Text = dt.Rows[0][0].ToString();
- //Tbx_date1.Text = dt.Rows[0]["contract_start"].ToString();
- //Tbx_date2.Text = dt.Rows[0]["contract_send"].ToString();
- //Tbx_date3.Text = dt.Rows[0]["Contract_finish"].ToString();
- //Tbx_person.Text = dt.Rows[0]["contract_person"].ToString();
- //Tbx_allmon.Text = dt.Rows[0]["contract_price"].ToString();
- //Tbx_count1.Text = dt.Rows[0]["product_book"].ToString();
- //Tbx_count2.Text = dt.Rows[0]["product_send"].ToString();
- //Tbx_price.Text = dt.Rows[0]["product_price"].ToString();
- //Ddl_customer.Items.FindByValue(dt.Rows[0]["custom_id"].ToString()).Selected = true;
- //Ddl_product.Items.FindByValue(dt.Rows[0]["product_id"].ToString()).Selected = true;
- //Ddl_state.Items.FindByValue(dt.Rows[0]["contract_state"].ToString()).Selected = true;
- //dt.Clear();
- connection.Open();
- OracleDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- Lbl_contractid.Text = dr["contract_id"].ToString();
- Tbx_date1.Text = dr["contract_start"].ToString();
- Tbx_date2.Text = dr["contract_send"].ToString();
- Tbx_date3.Text = dr["contract_finish"].ToString();
- Tbx_person.Text = dr["contract_person"].ToString();
- Tbx_allmon.Text = dr["contract_price"].ToString();
- Tbx_count1.Text = dr["product_book"].ToString();
- Tbx_count2.Text = dr["product_send"].ToString();
- Tbx_price.Text = dr["product_price"].ToString();
- Ddl_customer.Items.FindByValue(dr["custom_id"].ToString()).Selected = true;
- Ddl_product.Items.FindByValue(dr["product_id"].ToString()).Selected = true;
- Ddl_state.Items.FindByValue(dr["contract_state"].ToString()).Selected = true;
- }
- connection.Close();
- }
- protected void Btn_update_Click(object sender, EventArgs e)
- {
- }
- protected void Btn_back_Click(object sender, EventArgs e)
- {
- }
- }
Oracle数据库
- using System;
- using System.Data;
- using System.Configuration;
- using System.Collections;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
- using System.Data.OracleClient;
- public partial class Updatecontract : System.Web.UI.Page
- {
- string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
- protected void Page_Load(object sender, EventArgs e)
- {
- OracleConnection connection = new OracleConnection(connectionString);
- string sqlstr = "select * from customer";
- OracleCommand cmd = new OracleCommand(sqlstr, connection);
- connection.Open();
- OracleDataReader dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- Ddl_customer.Items.Add(new ListItem(dr["custom_name"].ToString(),dr["custom_id"].ToString()));
- }
- connection.Close();
- sqlstr="select * from product";
- cmd.CommandText=sqlstr;
- cmd.Connection=connection;
- connection.Open();
- dr=cmd.ExecuteReader();
- while (dr.Read())
- {
- Ddl_product.Items.Add(new ListItem(dr["product_name"].ToString(),dr["product_id"].ToString()));
- }
- connection.Close();
- if (!IsPostBack)
- Display();
- }
- public void Display()
- {
- OracleConnection connection = new OracleConnection(connectionString);
- string sqlstr = "select * from contract,contract_detail where contract.contract_id=contract_detail.contract_id and contract.contract_id=:contract_id";
- OracleCommand cmd = new OracleCommand(sqlstr, connection);
- cmd.Parameters.Add("contract_id", OracleType.Char).Value = Request.QueryString["contract_id"];
- DataTable dt = new DataTable();
- OracleDataAdapter da = new OracleDataAdapter(cmd);
- da.Fill(dt);
- Lbl_contractid.Text = dt.Rows[0][0].ToString();
- Tbx_date1.Text = dt.Rows[0]["contract_start"].ToString();
- Tbx_date2.Text = dt.Rows[0]["contract_send"].ToString();
- Tbx_date3.Text = dt.Rows[0]["Contract_finish"].ToString();
- Tbx_person.Text = dt.Rows[0]["contract_person"].ToString();
- Tbx_allmon.Text = dt.Rows[0]["contract_price"].ToString();
- Tbx_count1.Text = dt.Rows[0]["product_book"].ToString();
- Tbx_count2.Text = dt.Rows[0]["product_send"].ToString();
- Tbx_price.Text = dt.Rows[0]["product_price"].ToString();
- Ddl_customer.Items.FindByValue(dt.Rows[0]["custom_id"].ToString()).Selected = true;
- Ddl_product.Items.FindByValue(dt.Rows[0]["product_id"].ToString()).Selected = true;
- Ddl_state.Items.FindByValue(dt.Rows[0]["contract_state"].ToString()).Selected = true;
- dt.Clear();
- }
- protected void Btn_update_Click(object sender, EventArgs e)
- {
- }
- protected void Btn_back_Click(object sender, EventArgs e)
- {
- }
- }
或者:
SqlServer数据库
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class updatecontract : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//客户名称下拉列表框绑定
string settings = Convert.ToString(ConfigurationManager.ConnectionStrings["SqlServices"]);
//创建数据库连接
SqlConnection cn0 = new SqlConnection(settings);
cn0.Open();
string mysql = "select * from customer";
SqlCommand cm0 = new SqlCommand(mysql, cn0);
SqlDataReader dr0 = cm0.ExecuteReader();
while (dr0.Read())
{
Ddl_customer.Items.Add(new ListItem(dr0["Custom_name"].ToString(), dr0["Custom_id"].ToString()));
}
cn0.Close();
//产品名称下拉列表框绑定
cn0.Open();
string mysql1 = "select * from product";
SqlCommand cm1 = new SqlCommand(mysql1, cn0);
SqlDataReader dr1 = cm1.ExecuteReader();
while (dr1.Read())
{
Ddl_product.Items.Add(new ListItem(dr1["Product_name"].ToString(), dr1["Product_id"].ToString()));
}
cn0.Close();
// 在此处放置用户代码以初始化页面
if (!IsPostBack)
display();
}
public void display()
{
string settings = Convert.ToString(ConfigurationManager.ConnectionStrings["SqlServices"]);
//创建数据库连接
SqlConnection cn = new SqlConnection(settings);
string strsql = "select * from contract,contract_detail where contract.Contract_id=@Contract_id and contract.Contract_id=contract_detail.Contract_id";
SqlCommand cm = new SqlCommand(strsql, cn);
cm.Parameters.Add(new SqlParameter("@Contract_id", SqlDbType.Char, 10));
cm.Parameters["@Contract_id"].Value = Request.QueryString["Contract_id"];
cn.Open();
SqlDataReader dr = cm.ExecuteReader();
if (dr.Read())
{
Lbl_contractid.Text = Request.QueryString["Contract_id"];
Ddl_customer.SelectedItem.Value = dr["Custom_id"].ToString();
Ddl_customer.Items.FindByValue(dr["Custom_id"].ToString()).Selected = true;
Ddl_product.SelectedItem.Value = dr["Product_id"].ToString();
Ddl_product.Items.FindByValue(dr["Product_id"].ToString()).Selected = true;
Ddl_state.SelectedItem.Value = dr["Contract_state"].ToString();
Ddl_state.Items.FindByValue(dr["Contract_state"].ToString()).Selected = true;
Tbx_date1.Text = dr["Contract_start"].ToString();
Tbx_date3.Text = dr["Contract_send"].ToString();
Tbx_date2.Text = dr["Contract_finish"].ToString();
Tbx_person.Text = dr["Contract_person"].ToString();
Tbx_allmon.Text = dr["Contract_price"].ToString();
Tbx_count1.Text = dr["Product_book"].ToString();
Tbx_count2.Text = dr["Product_send"].ToString();
Tbx_price.Text = dr["Product_price"].ToString();
}
else
{
Lbl_contractid.Text = "error!";
}
cn.Close();
}
protected void Btn_update_Click(object sender, System.EventArgs e)
{
string settings = Convert.ToString(ConfigurationManager.ConnectionStrings["SqlServices"]);
//创建数据库连接
SqlConnection cn = new SqlConnection(settings);
if (Page.IsValid)
{
cn.Open();
SqlCommand cm = new SqlCommand("update_contract_1", cn);
cm.CommandType = CommandType.StoredProcedure;
try
{
cm.Parameters.Add(new SqlParameter("@Contract_id", SqlDbType.Char, 10));
cm.Parameters.Add(new SqlParameter("@Custom_id", SqlDbType.Char, 10));
cm.Parameters.Add(new SqlParameter("@Contract_state", SqlDbType.Int, 4));
cm.Parameters.Add(new SqlParameter("@Contract_start", SqlDbType.VarChar, 50));
cm.Parameters.Add(new SqlParameter("@Contract_send", SqlDbType.DateTime, 8));
cm.Parameters.Add(new SqlParameter("@Contract_finish", SqlDbType.DateTime, 8));
cm.Parameters.Add(new SqlParameter("@Contract_person", SqlDbType.Char, 10));
cm.Parameters.Add(new SqlParameter("@Contract_price", SqlDbType.Money, 8));
cm.Parameters["@Contract_id"].Value = Request.QueryString["Contract_id"];
cm.Parameters["@Custom_id"].Value = Ddl_customer.SelectedItem.Value;
cm.Parameters["@Contract_state"].Value = Ddl_state.SelectedItem.Value;
cm.Parameters["@Contract_start"].Value = Tbx_date1.Text;
cm.Parameters["@Contract_send"].Value = Tbx_date3.Text;
cm.Parameters["@Contract_finish"].Value = Tbx_date2.Text;
cm.Parameters["@Contract_person"].Value = Tbx_person.Text;
cm.Parameters["@Contract_price"].Value = Tbx_allmon.Text;
cm.ExecuteNonQuery();
Lbl_note.Text = "修改成功";
}
catch
{
Lbl_note.Text = "修改失败";
Lbl_note.Style["color"] = "red";
}
SqlCommand cm1 = new SqlCommand("update_contract_detail_1", cn);
cm1.CommandType = CommandType.StoredProcedure;
try
{
cm1.Parameters.Add(new SqlParameter("@Contract_id", SqlDbType.Char, 10));
cm1.Parameters.Add(new SqlParameter("@Product_id", SqlDbType.Char, 10));
cm1.Parameters.Add(new SqlParameter("@Product_book", SqlDbType.Int, 4));
cm1.Parameters.Add(new SqlParameter("@Product_send", SqlDbType.Int, 4));
cm1.Parameters.Add(new SqlParameter("@Product_price", SqlDbType.Money, 8));
cm1.Parameters["@Contract_id"].Value = Request.QueryString["Contract_id"];
cm1.Parameters["@Product_id"].Value = Ddl_product.SelectedItem.Value;
cm1.Parameters["@Product_book"].Value = Tbx_count1.Text;
cm1.Parameters["@Product_send"].Value = Tbx_count2.Text;
cm1.Parameters["@Product_price"].Value = Tbx_price.Text;
cm1.ExecuteNonQuery();
Lbl_note.Text = "修改成功";
}
catch
{
Lbl_note.Text = "修改失败";
Lbl_note.Style["color"] = "red";
}
cn.Close();
}
}
protected void Btn_back_Click(object sender, System.EventArgs e)
{
Response.Redirect("contract.aspx");
}
private void Cv_customer_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
string settings = Convert.ToString(ConfigurationManager.ConnectionStrings["SqlServices"]);
//创建数据库连接
SqlConnection cn = new SqlConnection(settings);
cn.Open();
SqlCommand cm = new SqlCommand("select * from customer where Custom_id=@Custom_id", cn);
cm.Parameters.Add("@Custom_id", SqlDbType.Char, 10);
cm.Parameters["@Custom_id"].Value = Ddl_customer.SelectedItem.Value;
SqlDataReader dr = cm.ExecuteReader();
if (dr.Read())
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
cn.Close();
}
}