C# ode,其中T1.CardCode=@selected”,连接); command.Parameters.AddWithValue(“@OpprId”,TextBox8.Text); SqlDataReader theReader=command.Exec
ode,其中T1.CardCode=@selected”,连接); command.Parameters.AddWithValue(“@OpprId”,TextBox8.Text); SqlDataReader theReader=command.ExecuteReader(); if(reader.Read()) { this.TextBox8.Text=theReader[“OpprId”].ToString(); } //command.Parameters.AddWithValue(“@CardCode”,选中); //数据集ds=新数据集(); //适配器。填充(CardCode); connection.Close(); //name2=id; } } 受保护的void DropDownList1\u SelectedIndexChanged(对象发送方,事件参数e) { DropDownList2.Items.Clear(); 所选字符串=DropDownList1.SelectedItem.Value; //string selected2=DropDownList2.SelectedItem.Value; DropDownList2.Visible=true; //DropDownList2.SelectedItem.Value=“”; 加载选项1(); //加载选项2(); SqlConnection=newsqlconnection(“数据源=1.2.3.5;初始目录=asdasd;持久安全信息=True;用户ID=abc;密码=asdfgh”); 使用(连接) { //SqlCommand theCommand=newsqlcommand(“从OOPR中选择CardCode、CardName、OpprId、CprCode、MaxSumLoc,其中CardCode=@CardCode”,connection); //SqlCommand命令命令=新的SqlCommand命令(“选择T1.CardCode,T1.CardName,T2.OpprId,T1.CNTCTPRN,T2.CprCode,T3.CntctCode,T3.Name从T1上的OCRD T1左连接OOPR T2。CardCode=T2上的T2.CardCode左连接OCPR T3。CprCode=T3.CntctCode,其中T1.CardCode=@CardCode”,连接); SqlCommand命令命令=新的SqlCommand(“从T1上的OCRD T1内部连接OCPR T3中选择T1.CardCode、T1.CardName、T3.CNTCTCCode、T3.Name,其中T3.CardCode=@CardCode”,连接); connection.Open(); command.Parameters.AddWithValue(“@CardCode”,选中); command.CommandType=CommandType.Text; //DropDownList2.SelectedValue=DropDownList1.SelectedValue; SqlDataReader theReader=command.ExecuteReader(); if(reader.Read()) { //坐第一排 //theReader.Read(); //设置文本框的值 this.TextBox1.Text=theReader[“CardCode”].ToString(); this.TextBox2.Text=theReader[“CardName”].ToString(); //this.TextBox5.Text=theReader[“CprCode”].ToString(); //this.TextBox8.Text=theReader[“OpprId”].ToString(); this.TextBox9.Text=theReader[“CntctCode”].ToString(); //this.DropDownList2.SelectedValue=selected; //this.DropDownList2.Text=theReader[“CntctPrsn”].ToString(); //this.DropDownList2.=已选择; this.DropDownList1.SelectedItem.Value=selected; //this.TextBox4.Text=theReader[“CntctCode”].ToString(); //this.TextBox3=reader.IsDBNull(TextBox3Index)?null:reader.GetInt32(TextBox3Index) //GenreID=reader.IsDBNull(genreIDIndex)?null:reader.GetInt32(genreIDIndex) //this.TextBox4.Text=theReader.GetString(3); //TextBox5.Text=theReader.GetString(4); //TextBox6.Text=theReader.GetString(5); //TextBox7.Text=theReader.GetString(6); } connection.Close(); } } 公共对象TextBox3Index{get;set;} //受保护的无效按钮1\u单击(对象发送者,事件参数e) // { //SqlConnection=newsqlconnection(); //connection.ConnectionString=System.Configuration.ConfigurationManager.ConnectionString[“TestDatabaseConnectionString 2”]。ConnectionString; //connection.Open(); //SqlCommand cmd=新的SqlCommand(); //cmd.CommandText=“从OOPR中选择*”; //cmd.Connection=连接; //SqlDataAdapter da=新的SqlDataAdapter(); //da.SelectCommand=cmd; //数据集ds=新数据集(); //da.填充(ds,“OOPR”); //SqlCommandBuilder cb=新的SqlCommandBuilder(da); //DataRow drow=ds.Tables[“OOPR”].NewRow(); //drow[“CardCode”]=TextBox1.Text; //drow[“CardName”]=TextBox2.Text; //drow[“OpprId”]=TextBox3.Text; //drow[“CprCode”]=TextBox4.Text; //drow[“MaxSumLoc”]=TextBox5.Text; //ds.Tables[“OOPR”].Rows.Add(drow); //da.更新(ds,“OOPR”); //字符串脚本=@“ //警报('信息已成功保存……!!!); // ;"; //Page.ClientScript.RegisterStartupScript(this.GetType(),“MyJScript 1”,脚本); // } 受保护的无效按钮1\u单击(对象发送者,事件参数e) { SqlConnection=newsqlconnection(“数据源=1.2.3.5;初始目录=asdasd;持久安全信息=True;用户ID=abc;密码=asdfgh”); 使用(连接) { //connection.Open(); //SqlCommand insert=new SqlCommand(“插入OOPR(CardCode、CardName、OpprId、CprCode、MaxSumLoc)值(@TextBox1、@TextBox2、@TextBox8、@TextBox4、@TextBox5)”,连接);/(“+TextBox1.Text+”、“+TextBox2.Text+”、“+DropDownList1.Text+”、“+TextBox4.Text+”),连接); SqlCommand insert=新的SqlCommand(“插入OOPR(CardCode、CardName、OpprId)值(@TextBox1、@TextBox2、@TextBox8)”,连接);/(“+TextBox1.Text+”C# ode,其中T1.CardCode=@selected”,连接); command.Parameters.AddWithValue(“@OpprId”,TextBox8.Text); SqlDataReader theReader=command.Exec,c#,asp.net,C#,Asp.net,ode,其中T1.CardCode=@selected”,连接); command.Parameters.AddWithValue(“@OpprId”,TextBox8.Text); SqlDataReader theReader=command.ExecuteReader(); if(reader.Read()) { this.TextBox8.Text=theReader[“OpprId”].ToString(); } //command.Parameters.AddWithValue(“@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
namespace StackOver
{
// public string name2,name1;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
LoadOptions();
//D;opDownList2.Visible=false;
//]]]DropDownList2. = "0"
//LoadOptions1();
}
}
protected void LoadOptions()
{
DataTable CardCode = new DataTable();
string id, name, newName, name2;
SqlConnection connection = new SqlConnection("Data Source=1.2.3.5;Initial Catalog=asdasd;Persist Security Info=True;User ID=abc;Password=asdfgh");
using (connection)
{
SqlDataAdapter adapter = new SqlDataAdapter("SELECT T1.CardCode , T1.CardName from ocrd T1 ", connection);
adapter.Fill(CardCode);
if (CardCode.Rows.Count > 0)
{
for (int i = 0; i < CardCode.Rows.Count; i++)
{
id = CardCode.Rows[i]["CardCode"].ToString();
name = CardCode.Rows[i]["CardName"].ToString();
newName = id + " ---- " + name;
DropDownList1.Items.Add(new ListItem(newName, id));
//DropDownList2.DataSource = CardCode;
//DropDownList2.DataValueField = "CardCode";
//DropDownList2.DataTextField = "CntctPrsn";
//DropDownList2.DataBind();
}
}
// adapter.Fill(CardCode);
//DropDownList1.DataValueField = "CardCode";
//DropDownList1.DataTextField = "CardCode";
//DropDownList1.DataBind();
}
}
protected void LoadOptions1()
{
DataTable CardCode = new DataTable();
// string name2;
string id, name, newName;
string selected = DropDownList1.SelectedItem.Value;
SqlConnection connection = new SqlConnection("Data Source=1.2.3.5;Initial Catalog=asdasd;Persist Security Info=True;User ID=abc;Password=asdfgh");
using (connection)
{
//SqlCommand theCommand = new SqlCommand("SELECT T1.CardCode , T1.CardName, T2.OpprId, T1.CntctPrsn,T2.CprCode,T3.CntctCode,T3.Name FROM OCRD T1 left join OOPR T2 on T1.CardCode=T2.CardCode left join OCPR T3 on T2.CprCode=T3.CntctCode where T1.CardCode=@CardCode ", connection);
SqlCommand theCommand = new SqlCommand("Select Name,CntctCode from OCPR where CardCode=@CardCode ", connection);
// SqlDataAdapter adapter = new SqlDataAdapter("SELECT T1.CardCode , T1.CardName, T2.OpprId,T1.CntctPrsn, T2.CprCode,T2.MaxSumLoc FROM OCRD T1 left join OOPR T2 on T1.CardCode=T2.CardCode where T1.CardCode=@selected", connection);
// SqlDataAdapter adapter = new SqlDataAdapter("SELECT T1.CardCode , T1.CardName, T2.OpprId,T1.CntctPrsn, T2.CprCode,T2.MaxSumLoc FROM OCRD T1 left join OOPR T2 on T1.CardCode=T2.CardCode where T1.CardCode=@selected", connection);
theCommand.Parameters.AddWithValue("@CardCode", selected);
SqlDataAdapter adapter = new SqlDataAdapter(theCommand);
//DataSet ds = new DataSet();
adapter.Fill(CardCode);
//name2 = id;
if (CardCode.Rows.Count > 0)
{
for (int i = 0; i < CardCode.Rows.Count; i++)
{
string name2 = CardCode.Rows[i]["Name"].ToString();
string contcode = CardCode.Rows[i]["CntctCode"].ToString();
string newName2 = contcode + " ---- " + name2;
DropDownList2.Items.Add(new ListItem(newName2, contcode));
//DropDownList2.DataSource = CardCode;
//DropDownList2.DataValueField = "CardCode";
//DropDownList2.DataTextField = "CntctPrsn";
//DropDownList2.DataBind();
}
}
}
}
protected void LoadOptions2()
{
DataTable OprId = new DataTable();
string id, name, newName, name2;
string selected = DropDownList1.SelectedItem.Value;
SqlConnection connection = new SqlConnection("Data Source=1.2.3.5;Initial Catalog=asdasd;Persist Security Info=True;User ID=abc;Password=asdfgh");
using (connection)
{
connection.Open();
//SqlCommand theCommand = new SqlCommand("SELECT T1.CardCode , T1.CardName, T2.OpprId, T1.CntctPrsn,T2.CprCode,T3.CntctCode,T3.Name FROM OCRD T1 left join OOPR T2 on T1.CardCode=T2.CardCode left join OCPR T3 on T2.CprCode=T3.CntctCode where T1.CardCode=@CardCode ", connection);
//SqlCommand theCommand = new SqlCommand("select max(T1.OpprId)+1 from OOPR T1 ", connection);
SqlCommand theCommand = new SqlCommand("select max(T1.OpprId)+1 as OpprId from OOPR T1;", connection);
theCommand.CommandType = CommandType.Text;
// SqlDataAdapter adapter = new SqlDataAdapter("SELECT T1.CardCode , T1.CardName, T2.OpprId,T1.CntctPrsn, T2.CprCode,T2.MaxSumLoc FROM OCRD T1 left join OOPR T2 on T1.CardCode=T2.CardCode where T1.CardCode=@selected", connection);
theCommand.Parameters.AddWithValue("@OpprId", TextBox8.Text);
SqlDataReader theReader = theCommand.ExecuteReader();
if (theReader.Read())
{
this.TextBox8.Text = theReader["OpprId"].ToString();
}
//theCommand.Parameters.AddWithValue("@CardCode", selected);
//DataSet ds = new DataSet();
// adapter.Fill(CardCode);
connection.Close();
//name2 = id;
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList2.Items.Clear();
string selected = DropDownList1.SelectedItem.Value;
// string selected2 = DropDownList2.SelectedItem.Value;
DropDownList2.Visible = true;
// DropDownList2.SelectedItem.Value ="";
LoadOptions1();
//LoadOptions2();
SqlConnection connection = new SqlConnection("Data Source=1.2.3.5;Initial Catalog=asdasd;Persist Security Info=True;User ID=abc;Password=asdfgh");
using (connection)
{
// SqlCommand theCommand = new SqlCommand("SELECT CardCode, CardName, OpprId, CprCode,MaxSumLoc FROM OOPR WHERE CardCode = @CardCode", connection);
// SqlCommand theCommand = new SqlCommand("SELECT T1.CardCode , T1.CardName, T2.OpprId, T1.CntctPrsn,T2.CprCode,T3.CntctCode,T3.Name FROM OCRD T1 left join OOPR T2 on T1.CardCode=T2.CardCode left join OCPR T3 on T2.CprCode=T3.CntctCode where T1.CardCode=@CardCode ", connection);
SqlCommand theCommand = new SqlCommand("SELECT T1.CardCode , T1.CardName,T3.CntctCode,T3.Name FROM OCRD T1 inner join OCPR T3 on T1.CardCode=T3.CardCode where T3.CardCode=@CardCode ", connection);
connection.Open();
theCommand.Parameters.AddWithValue("@CardCode", selected);
theCommand.CommandType = CommandType.Text;
// DropDownList2.SelectedValue = DropDownList1.SelectedValue;
SqlDataReader theReader = theCommand.ExecuteReader();
if (theReader.Read())
{
// Get the first row
// theReader.Read();
// Set the text box values
this.TextBox1.Text = theReader["CardCode"].ToString();
this.TextBox2.Text = theReader["CardName"].ToString();
// this.TextBox5.Text = theReader["CprCode"].ToString();
// this.TextBox8.Text = theReader["OpprId"].ToString();
this.TextBox9.Text = theReader["CntctCode"].ToString();
//this.DropDownList2.SelectedValue = selected;
//this.DropDownList2.Text = theReader["CntctPrsn"].ToString();
// this.DropDownList2. = selected;
this.DropDownList1.SelectedItem.Value = selected;
// this.TextBox4.Text = theReader["CntctCode"].ToString();
// this.TextBox3 = reader.IsDBNull(TextBox3Index) ? null : reader.GetInt32(TextBox3Index)
// GenreID = reader.IsDBNull(genreIDIndex) ? null : reader.GetInt32(genreIDIndex)
// this.TextBox4.Text = theReader.GetString(3);
// TextBox5.Text = theReader.GetString(4);
// TextBox6.Text = theReader.GetString(5);
// TextBox7.Text = theReader.GetString(6);
}
connection.Close();
}
}
public object TextBox3Index { get; set; }
// protected void Button1_Click(object sender, EventArgs e)
// {
// SqlConnection connection = new SqlConnection();
// connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["TestDataBaseConnectionString2"].ConnectionString;
// connection.Open();
// SqlCommand cmd = new SqlCommand();
// cmd.CommandText = "select * from OOPR";
// cmd.Connection = connection;
// SqlDataAdapter da = new SqlDataAdapter();
// da.SelectCommand = cmd;
// DataSet ds = new DataSet();
// da.Fill(ds, " OOPR");
// SqlCommandBuilder cb = new SqlCommandBuilder(da);
// DataRow drow = ds.Tables["OOPR"].NewRow();
// drow["CardCode"] = TextBox1.Text;
// drow["CardName"] = TextBox2.Text;
// drow["OpprId"] = TextBox3.Text;
// drow["CprCode"] = TextBox4.Text;
// drow["MaxSumLoc"] = TextBox5.Text;
// ds.Tables["OOPR"].Rows.Add(drow);
// da.Update(ds, " OOPR ");
// string script = @"<script language=""javascript"">
// alert('Information have been Saved Successfully.......!!!!!.');
// </script>;";
// Page.ClientScript.RegisterStartupScript(this.GetType(), "myJScript1", script);
// }
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection connection = new SqlConnection("Data Source=1.2.3.5;Initial Catalog=asdasd;Persist Security Info=True;User ID=abc;Password=asdfgh");
using (connection)
{
// connection.Open();
// SqlCommand insert = new SqlCommand("Insert into OOPR(CardCode, CardName, OpprId, CprCode,MaxSumLoc) values (@TextBox1,@TextBox2,@TextBox8,@TextBox4,@TextBox5 )", connection); //('" + TextBox1.Text + "','" + TextBox2.Text + "','" + DropDownList1.Text + "','" + TextBox4.Text + "')", connection);
SqlCommand insert = new SqlCommand("Insert into OOPR(CardCode, CardName, OpprId) values (@TextBox1,@TextBox2,@TextBox8 )", connection); //('" + TextBox1.Text + "','" + TextBox2.Text + "','" + DropDownList1.Text + "','" + TextBox4.Text + "')", connection);
insert.Parameters.AddWithValue("@TextBox1", TextBox1.Text);
insert.Parameters.AddWithValue("@TextBox2", TextBox2.Text);
// insert.Parameters.AddWithValue("@TextBox3", TextBox3.Text);
// insert.Parameters.AddWithValue("@TextBox4", TextBox4.Text);
// insert.Parameters.AddWithValue("@TextBox5", TextBox5.Text);
insert.Parameters.AddWithValue("@TextBox8", TextBox8.Text);
connection.Open();
// connection.CommandType=CommandType.Text;
// connection.commandType=CommandType.Text;
// try
// {
insert.ExecuteNonQuery();
connection.Close();
// }
//catch
//{
// TextBox5.Text = "Error when saving on database";
// connection.Close();
//}
//TextBox1.Text="";
//TextBox2.Text = "";
//TextBox3.Text = "";
//TextBox4.Text="";
}
}
protected void Button2_Click(object sender, EventArgs e)
{
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", true);
// this.close();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList2.Items.Clear();
LoadOptions1();
string selected2 = DropDownList2.SelectedItem.Value;
DropDownList2.Visible = true;
// DropDownList2.SelectedItem.Value ="";
//LoadOptions2();
SqlConnection connection = new SqlConnection("Data Source=1.2.3.5;Initial Catalog=asdasd;Persist Security Info=True;User ID=abc;Password=asdfgh");
using (connection)
{
// SqlCommand theCommand = new SqlCommand("SELECT CardCode, CardName, OpprId, CprCode,MaxSumLoc FROM OOPR WHERE CardCode = @CardCode", connection);
// SqlCommand theCommand = new SqlCommand("SELECT T1.CardCode , T1.CardName, T2.OpprId, T1.CntctPrsn,T2.CprCode,T3.CntctCode,T3.Name FROM OCRD T1 left join OOPR T2 on T1.CardCode=T2.CardCode left join OCPR T3 on T2.CprCode=T3.CntctCode where T1.CardCode=@CardCode ", connection);
SqlCommand theCommand = new SqlCommand("SELECT T3.CntctCode,T3.Name FROM OCRD T1 inner join OCPR T3 on T1.CardCode=T3.CardCode where T3.CntctCode=@CntctCode", connection);
connection.Open();
theCommand.Parameters.AddWithValue("@CntctCode", selected2);
theCommand.CommandType = CommandType.Text;
// DropDownList2.SelectedValue = DropDownList1.SelectedValue;
SqlDataReader theReader = theCommand.ExecuteReader();
if (theReader.Read())
{
// Get the first row
// theReader.Read();
// Set the text box values
//this.TextBox1.Text = theReader["CardCode"].ToString();
//this.TextBox2.Text = theReader["CardName"].ToString();
// this.TextBox5.Text = theReader["CprCode"].ToString();
// this.TextBox3.Text = theReader["OpprId"].ToString();
this.TextBox9.Text = theReader["CntctCode"].ToString();
//this.DropDownList2.SelectedValue = selected;
//this.DropDownList2.Text = theReader["CntctPrsn"].ToString();
// this.DropDownList2. = selected;
this.DropDownList2.SelectedItem.Value = selected2;
// this.TextBox3 = reader.IsDBNull(TextBox3Index) ? null : reader.GetInt32(TextBox3Index)
// GenreID = reader.IsDBNull(genreIDIndex) ? null : reader.GetInt32(genreIDIndex)
// this.TextBox4.Text = theReader.GetString(3);
// TextBox5.Text = theReader.GetString(4);
// TextBox6.Text = theReader.GetString(5);
// TextBox7.Text = theReader.GetString(6);
}
connection.Close();
}
}
}
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList2.Items.Clear(); //remove
LoadOptions1(); //remove
string selected2 = DropDownList2.SelectedItem.Value;
DropDownList2.Visible = true; //remove
//...