【发布时间】:2018-12-26 18:30:58
【问题描述】:
我在 C# 中使用 Visual Basic 参考向表中添加位置。 这在本地有效,但在将其发布到托管站点后会产生此错误: 当应用程序未在 UserInteractive 模式下运行时显示模式对话框或表单不是有效操作。指定 ServiceNotification 或 DefaultDesktopOnly 样式以显示来自服务应用程序的通知。
我的代码如下:
string addlocation = Microsoft.VisualBasic.Interaction.InputBox("Enter New Location", "Location", "", 600, 400);
if (addlocation == "" || addlocation == null)
{
Microsoft.VisualBasic.Interaction.MsgBox("Enter a Valid Name!", 0);
return;
}
using (var connection3 = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString))
{
connection.Open();
SqlCommand comm = new SqlCommand("SELECT COUNT(*) FROM Locations WHERE Locations = '" + addlocation + "'", connection);
Int32 count = Convert.ToInt32(comm.ExecuteScalar());
if (count == 0)
using (var cmd1 = new SqlCommand("INSERT INTO Locations(Locations) VALUES('" + addlocation + "');", connection3))
{
connection3.Open();
cmd1.ExecuteNonQuery();
connection3.Close();
Page.Response.Redirect(Page.Request.Url.ToString(), true);
connection3.Close();
}
else
{
Microsoft.VisualBasic.Interaction.MsgBox("Location Already Exists!", 0);
}
connection.Close();
}
【问题讨论】:
-
这是一个网站?你不能显示那些类型的对话框。即使没有导致错误,也没有人会看到它们。您可以在本地电脑上看到它,因为您以交互方式登录到服务器。
-
... 并使用参数来避免查询中的 sql 注入和格式错误。
标签: c# asp.net visual-studio