查了若干帖子都没解决我的问题!郁闷死了!
1、我先从sqlserver数据库中取出一个类型是SmallDateTime的数据放到文本框中
txtBirth.Text=chaxun.birth.ToShortDateString().Trim();//用来只显示日期
2、然后修改文本框中的日期(肯定合法日期),点击修改按钮,这时会触发一个远程过程loader中的修改函数
UpdateUserXX updatexx=loader.UpdateOneUser(DateTime.Parse(txtBirth.Text));这时系统报错:未处理的“System.FormatException”类型的异常出现在 mscorlib.dll 中。其他信息: 该字符串未被识别为有效的 DateTime。请各位高人指教这是怎么回事?
1、我先从sqlserver数据库中取出一个类型是SmallDateTime的数据放到文本框中
txtBirth.Text=chaxun.birth.ToShortDateString().Trim();//用来只显示日期
2、然后修改文本框中的日期(肯定合法日期),点击修改按钮,这时会触发一个远程过程loader中的修改函数
UpdateUserXX updatexx=loader.UpdateOneUser(DateTime.Parse(txtBirth.Text));这时系统报错:未处理的“System.FormatException”类型的异常出现在 mscorlib.dll 中。其他信息: 该字符串未被识别为有效的 DateTime。请各位高人指教这是怎么回事?
下面是我的远程代码:
public UpdateUserXX UpdateOneUser(DateTime birth1)
{
UpdateUserXX updatexx=new UpdateUserXX(DateTime.Parse);
try
{
dbConnection.Open();
SqlCommand cmd=new SqlCommand("UPDATE UserXx SET birth=birth1 ,dbConnection);
cmd.ExecuteNonQuery();
dbConnection.Close();
}
catch(Exception x) {//错误处理}
return updatexx;
}
假设数据库中就一个字段birth,里面就有一条记录2005-1-1
下面是序列化以便在局域网上传输:
[Serializable]
public class UpdateUserXX
{
private DateTime birth1;
public UpdateUserXX(DateTime birth1)
{
this.birth=birth1;
}
public DateTime birth
{
get { return birth1; }
set { birth1=value;}
}
}//UpdateUserXX对象结束
下面是我的远程代码:
public UpdateUserXX UpdateOneUser(DateTime birth1)
{
UpdateUserXX updatexx=new UpdateUserXX(DateTime.Parse);
try
{
dbConnection.Open();
SqlCommand cmd=new SqlCommand("UPDATE UserXx SET birth=birth1 ,dbConnection);
cmd.ExecuteNonQuery();
dbConnection.Close();
}
catch(Exception x) {//错误处理}
return updatexx;
}
假设数据库中就一个字段birth,里面就有一条记录2005-1-1
下面是序列化以便在局域网上传输:
[Serializable]
public class UpdateUserXX
{
private DateTime birth1;
public UpdateUserXX(DateTime birth1)
{
this.birth=birth1;
}
public DateTime birth
{
get { return birth1; }
set { birth1=value;}
}
}//UpdateUserXX对象结束
DateTime _date;
_date=DateTime.Parse(txtBirth.Text);
UpdateUserXX updatexx=loader.UpdateOneUser(_date);现在总该知道是错在哪里吧!
原来不用datetime类型,直接用string类型的字符串放进去就行
这大圈绕的!
那位高手知道怎么能让CS模式的系统能在互联网上运行,而不只局限于局域网!
上面的程序我是用remoting作的,一直不能通过公网,只能在局域网上
客户端:
HttpClientChannel channel=new HttpClientChannel();
ChannelServices.RegisterChannel(channel);
DBLoader loader = (DBLoader)Activator.GetObject(typeof(DBLoader),"http://YUANTT:9932/DBLoader");
服务器端:
HttpServerChannel channel = new HttpServerChannel(9932);
ChannelServices.RegisterChannel(channel);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(DBLoader),"DBLoader", WellKnownObjectMode.SingleCall);
远程类:
this.dbConnection = new System.Data.SqlClient.SqlConnection();
this.dbConnection.ConnectionString ="data source=YUANTT;initial catalog=gwcp_db;integrated security=SSPI;persist security info=False;workstation id=YUANTT;packet size=4096";