将字符串转换为datetime时...错误(不尝试解析/发送日期时间到服务器!) [英] when converting a string to datetime...error (not trying to parse/send datetime to the server!)
问题描述
我正在尝试使用存储过程和一些参数填充gridview。由于一些古怪的原因,我得到这个错误:
将字符串转换为datetime时解析字符串以获取将每个变量放入datetime对象之前的日期<很奇怪的是,我并没有尝试传递datetime参数,尽管存储过程确实使用fn CURDATE()来过滤一些对象,但是应该在sql中处理好吗?
错误来自dataAdapter.Fill行。
这是代码。
i am trying to populate a gridview with a stored procedure and some parameters. for some oddball reason, i get this error:
"when converting a string to datetime parse the string to take the date before putting each variable into the datetime object"
the odd thing is, i'm not trying to pass a datetime parameter, though the stored procedure does use the fn CURDATE() to filter some of the objects, but that should be taken care of in the sql right?
the error comes at the dataAdapter.Fill line.
here's the code.
ALTER PROCEDURE SearchAllPlayers
(
@personName,
@IDs
)
SELECT DISTINCT
person.personID, sports.sportsID, person.personName, sports.sport,
FROM sports INNER JOIN
person INNER JOIN
personSport ON personSport.personID = person.personID
INNER JOIN
personSport ON personSport.sportID = sports.sportsID
WHERE (person.personName LIKE '%' + @personName + '%')
AND
(person.regDate >= { fn CURDATE() }
AND
(sports.sportID IN
(SELECT ID FROM dbo.fnSplitter(@IDs) AS fnSplitter_1) OR @IDs = 0)
protected void Button1_Click(object sender, EventArgs e)
{
searchGrid();
}
protected void searchGrid()
{
SqlConnection conn = new SqlConnection(connSTR);
com = new SqlCommand();
conn.Open();
com.Connection = conn;
com.CommandText = "SearchAllPlayers";
com.CommandType = CommandType.StoredProcedure;
string StringWithDelimiter = string.Empty;
for (int i = 0; i < DropDownCheckBoxes1.Items.Count; i++)
{
if (DropDownCheckBoxes1.Items[i].Selected)
StringWithDelimiter += DropDownCheckBoxes1.Items[i].Value + ";";
}
com.Parameters.Add("@personName", SqlDbType.VarChar).Value = personName.Text;
com.Parameters.Add("@IDs", SqlDbType.VarChar).Value = StringWithDelimiter;
sqlDa = new SqlDataAdapter(com);
dS = new DataSet();
sqlDa.Fill(dS);
conn.Close();
GridView1.DataSource = dS;
GridView1.DataBind();
}
我不明白为什么我会遇到这个问题。请帮助
i cannot understand why i would have this issue. please help
推荐答案
而不是(person.regDate> = {fn CURDATE()}
使用
person.regDate> = GetDate()
Instead of (person.regDate >= { fn CURDATE() }
use
person.regDate >= GetDate()
这篇关于将字符串转换为datetime时...错误(不尝试解析/发送日期时间到服务器!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!