[英]Is there any possibilities to show the query with all parameters value in Visual Studio 2010
[英]Visual Studio 2010 Ignoring All query Errors?
我使用的是Visual Studio 2010和ASP.net c#语言。 我尝试从Excel工作表中读取然后将信息插入Microsoft SQL数据库,但我发现它忽略了查询语句中的错误。
for (int i = 0; i < objdatasetdto.Tables[0].Rows.Count; i++)
{
start_time = Convert.ToDateTime(objdatasetdto.Tables[0].Rows[i]["start"].ToString());
end_time = Convert.ToDateTime(objdatasetdto.Tables[0].Rows[i]["end"].ToString());
if (objdatasetdto.Tables[0].Rows[i]["Lecture_day"].ToString().Equals("1"))
{
try
{
query = "Insert into [M].[Lecture]([dd],[start_time],[end_time],[week_no],[sec_no],
[room_no],[building_no]) "+
values('" + Calendar1.SelectedDate.ToShortDateString() + "','" +
start_time.ToShortTimeString() + "','" + end_time.ToShortTimeString() +
"','1','" + objdatasetdto.Tables[0].Rows[i]["section_no"].ToString() + "','"
+ objdatasetdto.Tables[0].Rows[i]["room_no"].ToString() + "','"
+ objdatasetdto.Tables[0].Rows[i]["building_no"].ToString() + "');";
ifexist = new SqlCommand(query, cnn);
}
catch (Exception ex)
{
Response.Write(ex);
}
}//end if
}// end for loop
我写了[dd]列而不是[date]来测试它是否检测到错误。 但它完全忽略了它们。
我怎么解决这个问题。
您似乎没有执行SqlCommand。 尝试添加:
ifexist.ExecuteScalar();
你执行查询的地方?
您没有在以下任何一项中写过任何内容
如果您不执行,则查询如何编译查询以及如何预期错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.