【发布时间】:2015-07-27 15:36:13
【问题描述】:
我正在尝试使用 Windows 表单中的值对表进行简单的插入,但即使使用调试器并逐步检查似乎也没有出现错误并且插入失败。
我确实在服务器资源管理器中注意到,一旦我启动调试器,连接就会显示并关闭。我得到的连接字符串为:
SqlConnection con = new SqlConnection(UI.Properties.Settings.Default.PM_ConnectionString);
这是我的代码:
public void agregarLocal(String _nombre, String _telefono, int _preferencia, int _provincia, String _url, SqlConnection _con, String _descripcion = "")
{
using (_con)
{
_con.Open();
try
{
using (SqlCommand command = new SqlCommand(
"INSERT INTO Locales VALUES(@loc_nombre, @loc_telefono, @loc_descripcion, @loc_preferencia, @loc_provincia, @loc_url)", _con))
{
command.Parameters.Add(new SqlParameter("@loc_nombre", _nombre));
command.Parameters.Add(new SqlParameter("@loc_telefono", _telefono));
command.Parameters.Add(new SqlParameter("@loc_descripcion", _descripcion));
command.Parameters.Add(new SqlParameter("@loc_preferencia", _preferencia));
command.Parameters.Add(new SqlParameter("@loc_provincia", _provincia));
command.Parameters.Add(new SqlParameter("@loc_url", _url));
command.ExecuteNonQuery();
}
}
catch (SqlException ex)
{
Console.Write(ex.Message);
}
finally
{
if (_con.State == ConnectionState.Open)
_con.Close();
}
}
正如我之前所说,无法插入捕获没有显示。关于我可能遗漏的东西的任何提示?
编辑:添加了建议的更改,连接似乎已关闭,而整个过程正在进行 PMDatabase 仍然显示红色 x。
我还发现了一个我忽略的警告,尽管它似乎与插入数据库的过程无关,但它是:warning MSB3270: There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "WebKitBrowser, Version=0.5.0.0, Culture=neutral, PublicKeyToken=b967213f6d29a3be, processorArchitecture=x86", "x86". This mismatch may cause runtime failures. Please consider changing the targeted processor architecture of your project through the Configuration Manager so as to align the processor architectures between your project and references, or take a dependency on references with a processor architecture that matches the targeted processor architecture of your project.
【问题讨论】:
标签: c# visual-studio