using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;public partial class info : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=login;Integrated Security=SSPI;");
protected void Page_Load(object sender, EventArgs e)
{
this.TextBox5.Text = Convert.ToString(Session["usename"]);
conn.Open();
SqlCommand bb = new SqlCommand("select * from logininfo where usename='" + this.TextBox5.Text + "'", conn);
SqlDataReader cc = bb.ExecuteReader();
if (cc.Read())
{
this.TextBox2.Text = cc["usepwd"].ToString();
this.TextBox3.Text = cc["email"].ToString();
this.TextBox4.Text = cc["photo"].ToString();
string b;
b = cc["sex"].ToString();
if (b=="男")
this.DropDownList1.SelectedValue = "男";
else
this.DropDownList1.SelectedValue = "女";
}
conn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{ conn.Open();
SqlCommand cmd = new SqlCommand("update logininfo set usepwd='" + this.TextBox2.Text.ToString() + ",sex='" + this.DropDownList1.SelectedValue.ToString() + "',email='" + this.TextBox3.Text.ToString() + "',photo='" + this.TextBox4.Text.ToString() + "' where usename='"+this.TextBox5.Text+"'", conn);
SqlCommand cmd = new SqlCommand();
cmd.ExecuteNonQuery();
conn.Close();
Response.Write("<script>alert('修改成功,返回登录!');location.href='login.aspx';</script>");
}
}经过几次测试 发现update logininfo set usepwd='" + this.TextBox2.Text.ToString() + ",sex='" + this.DropDownList1.SelectedValue.ToString() + "',email='" + this.TextBox3.Text.ToString() + "',photo='" + this.TextBox4.Text.ToString() + "' 有错,传值不了 ,若我换成实参就可以。
数据库是
CREATE TABLE [master].[dbo].[logininfo] (
[id] int NOT NULL,
[usename] nvarchar (50) NOT NULL,
[usepwd] varchar (50) NOT NULL,
[sex] char (50) NOT NULL,
[email] varchar (50) NULL,
[photo] varchar (50) NULL
)
求助,弄了一个下午,不知道怎么弄啊!!!!!!
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;public partial class info : System.Web.UI.Page
{
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=login;Integrated Security=SSPI;");
protected void Page_Load(object sender, EventArgs e)
{
this.TextBox5.Text = Convert.ToString(Session["usename"]);
conn.Open();
SqlCommand bb = new SqlCommand("select * from logininfo where usename='" + this.TextBox5.Text + "'", conn);
SqlDataReader cc = bb.ExecuteReader();
if (cc.Read())
{
this.TextBox2.Text = cc["usepwd"].ToString();
this.TextBox3.Text = cc["email"].ToString();
this.TextBox4.Text = cc["photo"].ToString();
string b;
b = cc["sex"].ToString();
if (b=="男")
this.DropDownList1.SelectedValue = "男";
else
this.DropDownList1.SelectedValue = "女";
}
conn.Close();
}
protected void Button1_Click(object sender, EventArgs e)
{ conn.Open();
SqlCommand cmd = new SqlCommand("update logininfo set usepwd='" + this.TextBox2.Text.ToString() + ",sex='" + this.DropDownList1.SelectedValue.ToString() + "',email='" + this.TextBox3.Text.ToString() + "',photo='" + this.TextBox4.Text.ToString() + "' where usename='"+this.TextBox5.Text+"'", conn);
SqlCommand cmd = new SqlCommand();
cmd.ExecuteNonQuery();
conn.Close();
Response.Write("<script>alert('修改成功,返回登录!');location.href='login.aspx';</script>");
}
}经过几次测试 发现update logininfo set usepwd='" + this.TextBox2.Text.ToString() + ",sex='" + this.DropDownList1.SelectedValue.ToString() + "',email='" + this.TextBox3.Text.ToString() + "',photo='" + this.TextBox4.Text.ToString() + "' 有错,传值不了 ,若我换成实参就可以。
数据库是
CREATE TABLE [master].[dbo].[logininfo] (
[id] int NOT NULL,
[usename] nvarchar (50) NOT NULL,
[usepwd] varchar (50) NOT NULL,
[sex] char (50) NOT NULL,
[email] varchar (50) NULL,
[photo] varchar (50) NULL
)
求助,弄了一个下午,不知道怎么弄啊!!!!!!
SqlCommand cmd = new SqlCommand("update logininfo set usepwd='" + this.TextBox2.Text.ToString() + "',sex='" + this.DropDownList1.SelectedValue.ToString() + "',email='" + this.TextBox3.Text.ToString() + "',photo='" + this.TextBox4.Text.ToString() + "' where usename='"+this.TextBox5.Text+"'", conn);
这一段你拆成两句:
string updatesql="update logininfo set usepwd='" + this.TextBox2.Text.ToString() + "',sex='" + this.DropDownList1.SelectedValue.ToString() + "',email='" + this.TextBox3.Text.ToString() + "',photo='" + this.TextBox4.Text.ToString() + "' where usename='"+this.TextBox5.Text+"'";
SqlCommand cmd = new SqlCommand(updatesql, conn);
断点设在stirng updatesql那里,你就会知道啦。
自己动手 丰衣足食·
这句还有错吧
[usename] nvarchar (50) NOT NULL, "update logininfo set usepwd='" + this.TextBox2.Text.ToString() + ",sex='" + this.DropDownList1.SelectedValue.ToString() + "',email='" + this.TextBox3.Text.ToString() + "',photo='" + this.TextBox4.Text.ToString() + "' where usename=N'"+this.TextBox5.Text+"'"是不是因为少了个 N ?
cmd.ExecuteNonQuery();
conn.Close();
Response.Write("<script>alert('修改成功,返回登录!');location.href='login.aspx';</script>");
数据库的返回值就能说明修改成功了
原来我是输入22 男 的
发现语句是没问题的 只是按提交按钮后 把我原先的数据给还原了 没赋值上 所以数据库没改到杯具!!!
{
if(!ispostback){
......}}