'13' 附近有语法错误。

一剑 2007-06-12 01:28:56
运行如下代码出现:
'13' 附近有语法错误,不知道怎么解决,请教啊

try
{
string strIP = this.Request.ServerVariables.Get("HTTP_X_FORWARDED_FOR");
if( strIP == "" )
strIP = this.Request.ServerVariables.Get("REMOTE_ADDR");

SqlConnection objConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["RmmWeb"].ConnectionString);
StringBuilder strSQL = new StringBuilder("INSERT INTO msgboard(name,email,ttext,date,ip) values('");
strSQL.Append(this.TextBox1.Text + "','" + this.TextBox2.Text + "','" + this.TextBox3.Text );
strSQL.Append("'," + DateTime.Now + ",'" + strIP + "')");

SqlCommand objCommand = new SqlCommand(strSQL.ToString(), objConnection);
objConnection.Open();
objCommand.ExecuteNonQuery();
objConnection.Close();
this.Response.Redirect("Message.aspx?page=" + this.Request["page"]);
}
catch(Exception ex)
{
this.Label1.Text = ex.Message;
}
...全文
308 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
一剑 2007-06-12
  • 打赏
  • 举报
回复
解决了,我的方法如下:
string strIP = "";
if (HttpContext.Current.Request.ServerVariables["HTTP_VIA"] != null)
{
strIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
}
else
{
strIP = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
}
lovefootball 2007-06-12
  • 打赏
  • 举报
回复
http://www.cnblogs.com/winner/archive/2007/05/12/743614.html
lovefootball 2007-06-12
  • 打赏
  • 举报
回复
REMOTE_HOST
一剑 2007-06-12
  • 打赏
  • 举报
回复
呵呵,多谢上面的朋友的回复!!
再问一个如何取得客户端IP地址呢?
我用下面几行代码取的是空字符串啊?为什么怎么解决呢?
string strIP = this.Request.ServerVariables.Get("HTTP_X_FORWARDED_FOR");
if( strIP == "" )
strIP = this.Request.ServerVariables.Get("REMOTE_ADDR");
jiatong1981 2007-06-12
  • 打赏
  • 举报
回复
SqlCstrSQL.Append("'," + DateTime.Now + ",'" + strIP + "')");
============================================================================

strSQL.Append("','" + DateTime.Now + "','" + strIP + "')");
hyde100 2007-06-12
  • 打赏
  • 举报
回复
strSQL.Append("'," + DateTime.Now + ",'" + strIP + "')");
======================
很奇怪了
spkl1 2007-06-12
  • 打赏
  • 举报
回复
jf
xray2005 2007-06-12
  • 打赏
  • 举报
回复
strSQL.Append("','" + DateTime.Now.ToString() + "','" + strIP + "')");
lovefootball 2007-06-12
  • 打赏
  • 举报
回复
" + DateTime.Now + "
--》
'" + DateTime.Now + "'

你可以把SQL打印出来看看就知道了
jinjazz 2007-06-12
  • 打赏
  • 举报
回复
strSQL.Append("','" + DateTime.Now + "','" + strIP + "')");
amandag 2007-06-12
  • 打赏
  • 举报
回复
StringBuilder strSQL = new StringBuilder("INSERT INTO msgboard(name,email,ttext,date,ip) values('");
strSQL.Append(this.TextBox1.Text + "','" + this.TextBox2.Text + "','" + this.TextBox3.Text );
strSQL.Append("','" + DateTime.Now.ToString() + "','" + strIP + "')");

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧