c#中修改数据偶尔可以修改数据库里面的数据,很多时候不能修改。也不提示错误,请高手指教!!
代码是这样的表面层代码(首先验证数据库里面是否有相应数据,如果有再修改):DataSetReturndsr=newDataSetReturn();PubReturnpr=...
代码是这样的
表面层代码(首先验证数据库里面是否有相应数据,如果有再修改):
DataSetReturn dsr=new DataSetReturn ();
PubReturn pr = null;
denglu denglu=new denglu ();
if (yhm.Text != "" && mm.Text != "")
{
pr = denglu.dengluid(yhm.Text, mm.Text);
//dsr = denglu.dengluid1(yhm.Text, mm.Text);
//dataGridView1.DataSource = dsr.DataSet.Tables[0].DefaultView;
if (pr.MyReturn )
{
if (newmm.Text != newmm1.Text)
{
MessageBox.Show("您前后两次输入的密码不一致,请查证后再输");
newmm.Text = "";
newmm1.Text = "";
}
else
{
if (yhm.Text !="")
{
PubReturn pr1 = new PubReturn();
BLL.updatemm update = new BLL.updatemm();
pr1 = update.update(yhm.Text, newmm.Text);
if (pr1.MyReturn )
{
MessageBox.Show("密码修改成功");
yhm.Text = "";
mm.Text = "";
newmm.Text = "";
newmm1.Text = "";
}
}
else
MessageBox.Show("用户名不能为空!!");
}
}
else
{
yhm.Text = "";
mm.Text = "";
yhm.Focus();
MessageBox.Show("输入的用户名或密码有误,请查证后在输");
}
}
else
MessageBox.Show("用户名和密码不能为空!");
}
业务层:
PubReturn pr = new PubReturn();
AccessDate ad = new AccessDate();
public PubReturn update(string yhm, string newmm)
{
string str = "update gly set mm=@newmm where yhm=@yhm";
OleDbParameter[] param = new OleDbParameter[]
{
new OleDbParameter ("@newmm",OleDbType .VarChar ,20),
new OleDbParameter ("@yhm",OleDbType .VarChar ,20)
};
param[0].Value = yhm;
param[1].Value = newmm;
pr = ad.ExecuteCmdSQL(str, param);
return pr;
数据层:
public PubReturn ExecuteCmdSQL(string SQL, OleDbParameter[] Params)
{
OleDbCommand cmd = null;
PubReturn MyReturn = new PubReturn();
try
{
cmd = new OleDbCommand(SQL, objConn);
cmd.CommandType = CommandType.Text;
if (Params != null) { foreach (OleDbParameter parameter in Params) { if (parameter != null) { cmd.Parameters.Add(parameter); } } }
objConn.Open();
int i = cmd.ExecuteNonQuery();
MyReturn.MyReturn = true;
MyReturn.MyMessage = "数据保存成功!";
return MyReturn;
}
catch (Exception ex)
{
MyReturn.MyMessage = ex.Message.Replace("\n", "").Replace("\r", "").Replace("'", "");
return MyReturn;
}
finally
{ objConn.Close(); } 展开
表面层代码(首先验证数据库里面是否有相应数据,如果有再修改):
DataSetReturn dsr=new DataSetReturn ();
PubReturn pr = null;
denglu denglu=new denglu ();
if (yhm.Text != "" && mm.Text != "")
{
pr = denglu.dengluid(yhm.Text, mm.Text);
//dsr = denglu.dengluid1(yhm.Text, mm.Text);
//dataGridView1.DataSource = dsr.DataSet.Tables[0].DefaultView;
if (pr.MyReturn )
{
if (newmm.Text != newmm1.Text)
{
MessageBox.Show("您前后两次输入的密码不一致,请查证后再输");
newmm.Text = "";
newmm1.Text = "";
}
else
{
if (yhm.Text !="")
{
PubReturn pr1 = new PubReturn();
BLL.updatemm update = new BLL.updatemm();
pr1 = update.update(yhm.Text, newmm.Text);
if (pr1.MyReturn )
{
MessageBox.Show("密码修改成功");
yhm.Text = "";
mm.Text = "";
newmm.Text = "";
newmm1.Text = "";
}
}
else
MessageBox.Show("用户名不能为空!!");
}
}
else
{
yhm.Text = "";
mm.Text = "";
yhm.Focus();
MessageBox.Show("输入的用户名或密码有误,请查证后在输");
}
}
else
MessageBox.Show("用户名和密码不能为空!");
}
业务层:
PubReturn pr = new PubReturn();
AccessDate ad = new AccessDate();
public PubReturn update(string yhm, string newmm)
{
string str = "update gly set mm=@newmm where yhm=@yhm";
OleDbParameter[] param = new OleDbParameter[]
{
new OleDbParameter ("@newmm",OleDbType .VarChar ,20),
new OleDbParameter ("@yhm",OleDbType .VarChar ,20)
};
param[0].Value = yhm;
param[1].Value = newmm;
pr = ad.ExecuteCmdSQL(str, param);
return pr;
数据层:
public PubReturn ExecuteCmdSQL(string SQL, OleDbParameter[] Params)
{
OleDbCommand cmd = null;
PubReturn MyReturn = new PubReturn();
try
{
cmd = new OleDbCommand(SQL, objConn);
cmd.CommandType = CommandType.Text;
if (Params != null) { foreach (OleDbParameter parameter in Params) { if (parameter != null) { cmd.Parameters.Add(parameter); } } }
objConn.Open();
int i = cmd.ExecuteNonQuery();
MyReturn.MyReturn = true;
MyReturn.MyMessage = "数据保存成功!";
return MyReturn;
}
catch (Exception ex)
{
MyReturn.MyMessage = ex.Message.Replace("\n", "").Replace("\r", "").Replace("'", "");
return MyReturn;
}
finally
{ objConn.Close(); } 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询