string ConnSql = "Data Source=.;Initial Catalog=货品信息管理;Integrated Security=True";
//声明Conn为一个SQL Server连接对象
SqlConnection Conn = new SqlConnection(ConnSql);
Conn.Open(); //打开连接
SqlDataAdapter da = new SqlDataAdapter();
string SelectSql = "select * from tb_Goods";
da.SelectCommand = new SqlCommand(SelectSql, Conn);
SqlCommandBuilder scb = new SqlCommandBuilder(da); //为DataAdapter自动生成更新命令
DataSet ds = new DataSet();
da.Fill(ds);
Conn.Close();
DataRow NewRow = ds.Tables[0].NewRow(); //向DataSet第一个表对象中添加一个新行
NewRow["货品代码"] = TextBox1.Text; //为新行的各字段赋值
NewRow["生产商"] = TextBox2.Text;
NewRow["经办人"] = TextBox3.Text;
NewRow["采购日期"] = TextBox4.Text;
NewRow["货品名称"] = TextBox5.Text;
NewRow["单价"] = TextBox6.Text;
NewRow["数量"] = TextBox7.Text;本文来自辣.文'论.文·网原文请找腾讯324,9114
ds.Tables[0].Rows.Add(NewRow); //将新建行添加到DataSet第一个表对象中
da.Update(ds); //将DataSet中数据变化提交到数据库(更新数据库)
Response.Write("<script language=javascript>alert('新记录添加成功,请单击“返回”回到主页面!');</script>");
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
}
protected void BackHome_Click1(object sender, EventArgs e)
{
Response.Redirect("default.aspx");
}
4信息修改模块
向页面添加一个HTML表格,然后一个DropDownList,6个textBox和2个Button,1个sqldataSurce.配置salDataSource1,执行控件任务菜单的“配置数据源”命令,在显示的“配置Select语句”页面中应注意选择“制定来自表或着视图的列”项,并在下面的列选中货品代码项,单击ORDER BY选择按升序排列返回值。2个botton,把他的ID改为Submit,BackHome.TEXT改为提交和返回代码如下:
using System.Data.SqlClient;
protected void Page_Load(object sender, EventArgs e)
{
this.Title = "更新记录";
DropDownList1.AutoPostBack = true;
if (!IsPostBack)
{
string ConnSql = "Data Source=.;Initial Catalog=货品信息管理;Integrated Security=True";
//声明Conn为一个SQL Server连接对象
SqlConnection Conn = new SqlConnection(ConnSql);
Conn.Open(); //打开连接
SqlDataAdapter da = new SqlDataAdapter();
string SelectSql = "select * from tb_Goods";
da.SelectCommand = new SqlCommand(SelectSql, Conn);
SqlCommandBuilder scb = new SqlCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds);
Conn.Close();
DataRow MyRow = ds.Tables[0].Rows[0];
TextBox1.Text = MyRow["生产商"].ToString();
TextBox2.Text = MyRow["经办人"].ToString();
TextBox3.Text = MyRow["采购日期"].ToString();
TextBox4.Text = MyRow["货品名称"].ToString();
TextBox5.Text = MyRow["单价"].ToString();
TextBox6.Text = MyRow["数量"].ToString();
}
}本文来自辣.文'论.文·网原文请找腾讯3249.114
protected void SubMit_Click(object sender, EventArgs e)
{
string ConnSql = "Data Source=.;Initial Catalog=货品信息管理
论文网http://www.751com.cn/ ;Integrated Security=True";
SqlConnection Conn = new SqlConnection(ConnSql);
Conn.Open(); //打开连接
SqlDataAdapter da = new SqlDataAdapter();
string SelectSql = "select * from tb_Goods where 货品代码 ='" + DropDownList1.Text + "'";
da.SelectCommand = new SqlCommand(SelectSql, Conn);
SqlCommandBuilder scb = new SqlCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds);
DataRow MyRow = ds.Tables[0].Rows[0]; //从表对象中得到要修改的行
MyRow["生产商"] = TextBox1.Text;
MyRow["经办人"] = TextBox2.Text;
MyRow["采购日期"] = TextBox3.Text;
MyRow["货品名称"] = TextBox4.Text;
MyRow["单价"] = TextBox5.Text;
MyRow["数量"] = TextBox6.Text;
da.Update(ds); //提交更新
Response.Write("<script language=javascript>alert('记录更新成功,请单击“返回”按钮回到主页面!');</script>");
上一页 [1] [2] [3] [4] 下一页
asp.net+sqlserver货品信息管理系统源代码+实验报告+运行流程图 第3页下载如图片无法显示或论文不完整,请联系qq752018766