我不知道为什么但是当我想插入图像并保存时,SQLException会出现错误(?)
namespace Project
{
class Connection
{
private SqlConnection con;
private string connectString = @"Data Source=.\SQLEXPRESS;AttachDbFilename=" + Application.StartupPath + @"\Database1.mdf;Integrated Security=True;User Instance=True";
private DataTable dTable;
private SqlDataAdapter adapt;
private SqlDataReader read;
private SqlCommand cmd;
public Connection()
{
con = new SqlConnection(connectString);
}
public DataTable executeQuery(string query)
{
try
{
if (con.State != ConnectionState.Closed)
{
con.Close();
}
}
catch(Exception e)
{
MessageBox.Show("Error in database: "+e);
}
con.Open();
dTable = new DataTable();
adapt = new SqlDataAdapter(query, connectString);
adapt.Fill(dTable);
return dTable;
}
public void executeUpdate(string query)
{
try
{
if (con.State != ConnectionState.Closed)
{
con.Close();
}
}
catch (Exception e)
{
MessageBox.Show("Error in database: " + e);
}
con.Open();
cmd = con.CreateCommand();
cmd.CommandText = query;
read = cmd.ExecuteReader(); // this is the error
}
}
}