小弟刚学asp.net没多久,,作了个网站,
在调用后台模块时,引用处理前台数据时出错...
我把前后台部分代码贴出来,,大家帮看下哪地方出错,是不是ref这个形参?
一,前台部分
UserDB UserNew=new UserDB();
UserInfo NewInfo=new UserInfo();NewInfo.UserAccount=useraccount.Text;
NewInfo.UserPass=pass1.Text;
NewInfo.UserName=username.Text;
NewInfo.UserGender=usergender.SelectedItem.Text;
NewInfo.UserId=0;
UserNew.AddUserInfo(NewInfo);//这里调后台过程二,后台部分
(1)User部分
public void AddUserInfo(UserInfo MyUserInfo)
{
//添加一个新用户的资料
Change4SQL(ref MyUserInfo); //到这里调后台的第二部分sql部分
string MySQL="INSERT INTO [User] ";
MySQL += "(UserAccount, UserPass, UserName, UserGender, ";
MySQL += "UserLastAccess, UserRegTime) VALUES ('";
MySQL += MyUserInfo.UserAccount.Replace(",","''") + "', '";
MySQL += MyUserInfo.UserPass.Replace(",","''") + "', '";
MySQL += MyUserInfo.UserName.Replace(",","''") + "', '";
MySQL += MyUserInfo.UserGender.Replace(",","''") + "', '"; //DataTime类型的SQL语句是否要加#...#限定符
MySQL += DateTime.Now + "', '";
MySQL += DateTime.Now + "')"; SQLDB MyDB=new SQLDB();
MyDB.strSQL=MySQL;
MyDB.ExecuteSQL();
}(2)SQL部分public string Change4Saving(string OriginalString)
{
return OriginalString.Replace("'","''");
}
执行到这里就出错了,数据引用出错,不知道我的ref使用的是否正确?
高手朋友们请指教了
在调用后台模块时,引用处理前台数据时出错...
我把前后台部分代码贴出来,,大家帮看下哪地方出错,是不是ref这个形参?
一,前台部分
UserDB UserNew=new UserDB();
UserInfo NewInfo=new UserInfo();NewInfo.UserAccount=useraccount.Text;
NewInfo.UserPass=pass1.Text;
NewInfo.UserName=username.Text;
NewInfo.UserGender=usergender.SelectedItem.Text;
NewInfo.UserId=0;
UserNew.AddUserInfo(NewInfo);//这里调后台过程二,后台部分
(1)User部分
public void AddUserInfo(UserInfo MyUserInfo)
{
//添加一个新用户的资料
Change4SQL(ref MyUserInfo); //到这里调后台的第二部分sql部分
string MySQL="INSERT INTO [User] ";
MySQL += "(UserAccount, UserPass, UserName, UserGender, ";
MySQL += "UserLastAccess, UserRegTime) VALUES ('";
MySQL += MyUserInfo.UserAccount.Replace(",","''") + "', '";
MySQL += MyUserInfo.UserPass.Replace(",","''") + "', '";
MySQL += MyUserInfo.UserName.Replace(",","''") + "', '";
MySQL += MyUserInfo.UserGender.Replace(",","''") + "', '"; //DataTime类型的SQL语句是否要加#...#限定符
MySQL += DateTime.Now + "', '";
MySQL += DateTime.Now + "')"; SQLDB MyDB=new SQLDB();
MyDB.strSQL=MySQL;
MyDB.ExecuteSQL();
}(2)SQL部分public string Change4Saving(string OriginalString)
{
return OriginalString.Replace("'","''");
}
执行到这里就出错了,数据引用出错,不知道我的ref使用的是否正确?
高手朋友们请指教了
解决方案 »
- javascript如何取到hidden的值?
- 【分享】.net面试问答(大汇总)
- 如何动态获取GridView的DataKeyName值,并根据每行DataKeyName值动态给每行添加一个div,并往div中添加数据?
- 在一个页面里同时使用Repeater和gridView两个控件需要用2个objectDataSource吗?
- 求1到12的正則表達式,或說是月份的正則表達式
- 请问如何实现鼠标点击地图,地图放大的效果??在线等待
- 请问怎么实现...搞晕了
- dropdownlist enabled
- SingleOrDefault 不存在返回的默认值是什么?
- 员工基本信息管理系统怎么做?
- 判断session是否存在
- ASP.NET移动web应用程序与WML写的WAP网站有什么不同?应用范围的不同?各有什么么优缺点?
To use a ref parameter, the argument must explicitly be passed to the method as a ref argument. The value of a ref argument will be passed to the ref parameter.
An argument passed to a ref parameter must first be initialized. Compare this to an out parameter, whose argument does not have to be explicitly initialized before being passed to an out parameter.
A property is not a variable and cannot be passed as a ref parameter.
An overload will occur if declarations of two methods differ only in their use of ref. However, it is not possible to define an overload that only differs by ref and out. For example, the following overload declarations are valid:
class MyClass
{
public void MyMethod(int i) {i = 10;}
public void MyMethod(ref int i) {i = 10;}
}
but the following overload declarations are invalid:
class MyClass
{
public void MyMethod(out int i) {i = 10;}
public void MyMethod(ref int i) {i = 10;}
}
For information on passing an array, see Passing Arrays Using ref and out.
Example
// cs_ref.cs
using System;
public class MyClass
{
public static void TestRef(ref char i)
{
// The value of i will be changed in the calling method
i = 'b';
} public static void TestNoRef(char i)
{
// The value of i will be unchanged in the calling method
i = 'c';
} // This method passes a variable as a ref parameter; the value of the
// variable is changed after control passes back to this method.
// The same variable is passed as a value parameter; the value of the
// variable is unchanged after control is passed back to this method.
public static void Main()
{
char i = 'a'; // variable must be initialized
TestRef(ref i); // the arg must be passed as ref
Console.WriteLine(i);
TestNoRef(i);
Console.WriteLine(i);
}
}
{
//修改用户基本资料
StringFilter MyFilter=new StringFilter(); //调用sqldb.cs中定义类的方法
MyInfo.UserAccount=MyFilter.Change4Saving(MyInfo.UserAccount);
MyInfo.UserPass=MyFilter.Change4Saving(MyInfo.UserPass);
MyInfo.UserName=MyFilter.Change4Saving(MyInfo.UserName);
........
}