在将 varchar 值 'year1' 转换成数据类型 int 时失败。的问题

FeelTouch Labs
博客专家认证
2009-07-19 10:32:53
//创建连接桥并从数据库检索数据
int year1, month1, day1;
year1 = Int16.Parse(DropDownList1.SelectedItem.Text);
month1 = Int16.Parse(DropDownList2.SelectedItem.Text);
day1 = Int16.Parse(DropDownList3.SelectedItem.Text);
SqlDataAdapter sda = new SqlDataAdapter("select * from Attendance,Member WHERE Attendance.Number=Member.Number and year(Time)='year1'and month(Time)='month1' and day(Time)='day1'order by Name asc", S601_myConn);
我的意思是从数据库得到三个下拉菜单组合的时间(即某一天的记录),但提示错误
...全文
265 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
liangCK 2009-07-19
  • 打赏
  • 举报
回复
SqlDataAdapter sda = new SqlDataAdapter("select * from Attendance,Member "
+ " WHERE Attendance.Number=Member.Number "
+ " and year(Time)=" + year1.ToString()
+ " and month(Time)=" + month1.ToString()
+ " and day(Time)=" + day1.ToString()
+ " order by Name asc", S601_myConn);

--建议使用参数化方式.
fcuandy 2009-07-19
  • 打赏
  • 举报
回复
这是c#最简单的语法问题吧
liangCK 2009-07-19
  • 打赏
  • 举报
回复
SqlDataAdapter sda = new SqlDataAdapter("select * from Attendance,Member "
+ " WHERE Attendance.Number=Member.Number "
+ " and year(Time)=" + year1.ToString()
+ " and month(Time)=" + month1.ToString()
+ " and day(Time)=" + day1.ToString()
+ " order by Name asc", S601_myConn);

--建议使用参数化方式.
liangCK 2009-07-19
  • 打赏
  • 举报
回复
SqlDataAdapter sda = new SqlDataAdapter("select * from Attendance,Member 
WHERE Attendance.Number=Member.Number
and year(Time)=" + year1.ToString() + '
and month(Time)=" + month1.ToString() + '
and day(Time)=" + day1.ToString() + '
order by Name asc", S601_myConn);

--建议使用参数化方式.
liangCK 2009-07-19
  • 打赏
  • 举报
回复
int year1 = 10;

string sql = "select year";



string sql2 = "select " + year1;

是不一样的.
仙道彰 2009-07-19
  • 打赏
  • 举报
回复
哦看错了,也写错了
试试
year(Time)=year1
仙道彰 2009-07-19
  • 打赏
  • 举报
回复
.net

试试year(Time)='“+year1+"'

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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