http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=8ADE535F-AD40-4DE3-A962-A64B4FAF12C4
解决方案 »
- 优酷网Flash分享链接怎么实现?
- 页面传递参数出错
- 跪求xml解决办法.
- asp.et +sql server 如何控制连接在服务器上的机器台数
- 再来一道关于DropDownList的趣题,不信邪的都进来!!!
- 各位大哥,求助ASP.NET的部署与安装问题
- textbox在c#中如何实现全选
- 高分悬赏,写一个像[阿里巴巴]首页行业显示的2重循环代码!在线等待! 解决马上结帖!谢谢!
- 如何利用GridView 输出文章
- 有谁能和我说说asp.net的真正内容及它与asp的区别吗?我正在学asp
- 如何去除自动刷新问题. 不是服务器控件的问题
- .Net安全问题: 任何一个textbox中输入字符串 <BR> 提交都会出现错误.怎么办?
也可以这样:
DataGrid1.DataBind();
Response.Redirect("当前页面的.aspx")
另外,你的DataGrid1 的EnableStateView 要为 True
sqlDA.Fill(dsFactory);
DataGrid1.DataBind();
另外,我全部是用的控件,sqldataadpter,sqlconnection,sqlcommand,是不是这个原因啊。
sqlDA.Fill(dsFactory);
DataGrid1.DataBind();
另外,我全部是用的控件,sqldataadpter,sqlconnection,sqlcommand,是不是这个原因啊。
/////////////不是,你必须重新对当前页请求一次才能看见最新的结果
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;namespace localhost
{
/// <summary>
/// manage_factory 的摘要说明。
/// </summary>
public class admin_factory : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txt_factory_name;
protected System.Web.UI.WebControls.TextBox txt_factory_description;
protected System.Web.UI.WebControls.DropDownList DropDownList_parent;
protected System.Web.UI.WebControls.RadioButton radio1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.RadioButton radio2;
protected System.Web.UI.WebControls.Label Label1;
protected System.Data.SqlClient.SqlDataAdapter sqlDA;
protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
protected System.Data.SqlClient.SqlConnection sqlConn;
protected System.Data.SqlClient.SqlCommand sqlCmd;
protected localhost.dsFactory dsFactory;
protected System.Web.UI.WebControls.Button bt_confirm; private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
/* string sql = "SELECT FactoryID, FactoryCName, FactoryEName, FactoryCountory, FactoryDes, FactoryURL FROM tb_factory";
SqlConnection Conn = new SqlConnection("workstation id=ZORRO2003;packet size=4096;user id=sa;data source=127.0.0.1;persist security info=True;initial catalog=ecarzone;password=ease2pass");
SqlDataAdapter sqlADP = new SqlDataAdapter();
sqlADP.SelectCommand = new SqlCommand(sql,Conn);
SQLDataSetCommand cmd = new SQLDataSetCommand(sql,Conn); DataSet aa = new DataSet();
int iRowCount = cmd.FillDataSet(aa);
*/ sqlDA.Fill(dsFactory);
DataGrid1.DataBind();
//Response.Write("<SCRIPT LANGUAGE='javascript'>alert('刷新了!');</SCRIPT>"); } #region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.sqlDA = new System.Data.SqlClient.SqlDataAdapter();
this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
this.sqlConn = new System.Data.SqlClient.SqlConnection();
this.sqlCmd = new System.Data.SqlClient.SqlCommand();
this.dsFactory = new localhost.dsFactory();
((System.ComponentModel.ISupportInitialize)(this.dsFactory)).BeginInit();
this.bt_confirm.Click += new System.EventHandler(this.bt_confirm_Click);
this.DataGrid1.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_CancelCommand);
this.DataGrid1.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_EditCommand);
this.DataGrid1.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_UpdateCommand);
this.DataGrid1.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_DeleteCommand);
//
// sqlDA
//
this.sqlDA.DeleteCommand = this.sqlDeleteCommand1;
this.sqlDA.InsertCommand = this.sqlInsertCommand1;
this.sqlDA.SelectCommand = this.sqlSelectCommand1;
this.sqlDA.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
new System.Data.Common.DataTableMapping("Table", "tb_factory", new System.Data.Common.DataColumnMapping[] {
new System.Data.Common.DataColumnMapping("FactoryID", "FactoryID"),
new System.Data.Common.DataColumnMapping("FactoryCName", "FactoryCName"),
new System.Data.Common.DataColumnMapping("FactoryEName", "FactoryEName"),
this.sqlDA.UpdateCommand = this.sqlUpdateCommand1;
//
// sqlSelectCommand1
//
this.sqlSelectCommand1.CommandText = "SELECT FactoryID, FactoryCName, FactoryEName, FactoryCountory, FactoryDes, Factor" +
"yURL FROM tb_factory";
this.sqlSelectCommand1.Connection = this.sqlConn;
//
// sqlInsertCommand1
//
this.sqlInsertCommand1.CommandText = @"INSERT INTO tb_factory(FactoryCName, FactoryEName, FactoryCountory, FactoryDes, FactoryURL) VALUES (@FactoryCName, @FactoryEName, @FactoryCountory, @FactoryDes, @FactoryURL); SELECT FactoryID, FactoryCName, FactoryEName, FactoryCountory, FactoryDes, FactoryURL FROM tb_factory WHERE (FactoryID = @@IDENTITY)";
this.sqlInsertCommand1.Connection = this.sqlConn;
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FactoryCName", System.Data.SqlDbType.VarChar, 50, "FactoryCName"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FactoryEName", System.Data.SqlDbType.VarChar, 50, "FactoryEName"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FactoryCountory", System.Data.SqlDbType.VarChar, 50, "FactoryCountory"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FactoryDes", System.Data.SqlDbType.VarChar, 2147483647, "FactoryDes"));
this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FactoryURL", System.Data.SqlDbType.VarChar, 200, "FactoryURL"));
//
// sqlUpdateCommand1
//
this.sqlUpdateCommand1.CommandText = @"UPDATE tb_factory SET FactoryCName = @FactoryCName, FactoryEName = @FactoryEName, FactoryCountory = @FactoryCountory, FactoryDes = @FactoryDes, FactoryURL = @FactoryURL WHERE (FactoryID = @Original_FactoryID) AND (FactoryCName = @Original_FactoryCName OR @Original_FactoryCName IS NULL AND FactoryCName IS NULL) AND (FactoryCountory = @Original_FactoryCountory OR @Original_FactoryCountory IS NULL AND FactoryCountory IS NULL) AND (FactoryEName = @Original_FactoryEName OR @Original_FactoryEName IS NULL AND FactoryEName IS NULL) AND (FactoryURL = @Original_FactoryURL OR @Original_FactoryURL IS NULL AND FactoryURL IS NULL); SELECT FactoryID, FactoryCName, FactoryEName, FactoryCountory, FactoryDes, FactoryURL FROM tb_factory WHERE (FactoryID = @FactoryID)";
this.sqlUpdateCommand1.Connection = this.sqlConn;
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FactoryCName", System.Data.SqlDbType.VarChar, 50, "FactoryCName"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FactoryEName", System.Data.SqlDbType.VarChar, 50, "FactoryEName"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FactoryCountory", System.Data.SqlDbType.VarChar, 50, "FactoryCountory"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FactoryDes", System.Data.SqlDbType.VarChar, 2147483647, "FactoryDes"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FactoryURL", System.Data.SqlDbType.VarChar, 200, "FactoryURL"));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_FactoryID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FactoryID", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_FactoryCName", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FactoryCName", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_FactoryCountory", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FactoryCountory", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_FactoryEName", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FactoryEName", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_FactoryURL", System.Data.SqlDbType.VarChar, 200, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FactoryURL", System.Data.DataRowVersion.Original, null));
this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@FactoryID", System.Data.SqlDbType.Int, 4, "FactoryID"));
//
// sqlDeleteCommand1
//
this.sqlDeleteCommand1.CommandText = @"DELETE FROM tb_factory WHERE (FactoryID = @Original_FactoryID) AND (FactoryCName = @Original_FactoryCName OR @Original_FactoryCName IS NULL AND FactoryCName IS NULL) AND (FactoryCountory = @Original_FactoryCountory OR @Original_FactoryCountory IS NULL AND FactoryCountory IS NULL) AND (FactoryEName = @Original_FactoryEName OR @Original_FactoryEName IS NULL AND FactoryEName IS NULL) AND (FactoryURL = @Original_FactoryURL OR @Original_FactoryURL IS NULL AND FactoryURL IS NULL)";
this.sqlDeleteCommand1.Connection = this.sqlConn;
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_FactoryID", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FactoryID", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_FactoryCountory", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FactoryCountory", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_FactoryEName", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FactoryEName", System.Data.DataRowVersion.Original, null));
this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_FactoryURL", System.Data.SqlDbType.VarChar, 200, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "FactoryURL", System.Data.DataRowVersion.Original, null));
//
// sqlConn
//
this.sqlConn.ConnectionString = "workstation id=ZORRO2003;packet size=4096;user id=sa;data source=\"127.0.0.1\";pers" +
"ist security info=True;initial catalog=ecarzone;password=ease2pass";
//
// sqlCmd
//
this.sqlCmd.Connection = this.sqlConn;
//
// dsFactory
//
this.dsFactory.DataSetName = "dsFactory";
this.dsFactory.Locale = new System.Globalization.CultureInfo("zh-CN");
this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.dsFactory)).EndInit(); }
#endregion private void bt_confirm_Click(object sender, System.EventArgs e)
{
if(Page.IsValid == true)
{
if(sqlConn.State!=ConnectionState.Open)
{
string factory_country;
if(radio1.Checked == true)
{
factory_country = "国内";
}
else
{
factory_country = "国外";
};
sqlCmd.CommandText = "INSERT INTO tb_factory (FactoryCName, FactoryDes, FactoryCountory) VALUES ('" + txt_factory_name.Text + "','" + txt_factory_description.Text + "','"+ factory_country +"')";
sqlConn.Open();
}
sqlCmd.ExecuteNonQuery();
sqlDA.Fill(dsFactory);
DataGrid1.DataBind();
txt_factory_name.Text = "";
txt_factory_description.Text = "";
}
}
不然你就要进行两次绑定才能解决问题。