0
我不知道爲什麼,但是當我想插入圖像並保存,它會通過的SQLException錯誤是未處理未處理(?)的SQLException是用C#
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
}
}
}
實際的代碼執行你的查詢在try/catch子句之外。 – aevitas
@aevitas所以我應該如何處理這個ExecuteReader?有點困惑這個錯誤 – user3194066
你執行什麼查詢? –