public void AddClient(Client obj){
try{
using(System.Data.SQLite.SQLiteConnection conn = stock.db.SqlLiteConnection.getSQLLiteConnection()){
System.Data.SQLite.SQLiteCommand cmd = conn.CreateCommand();
string sql="insert into Client (email,firstName,lastName,telephone,address,city,state,zip,web) values(@email,@firstName,@lastName,@telephone,@address,@city,@state,@zip,@web)";
cmd.CommandText = sql;
cmd.Parameters.AddWithValue("@email", obj.Email);
cmd.Parameters.AddWithValue("@firstName", obj.FirstName);
cmd.Parameters.AddWithValue("@lastName", obj.LastName);
cmd.Parameters.AddWithValue("@telephone", obj.Telephone);
cmd.Parameters.AddWithValue("@address", obj.Address);
cmd.Parameters.AddWithValue("@city", obj.City);
cmd.Parameters.AddWithValue("@state", obj.State);
cmd.Parameters.AddWithValue("@zip", obj.Zip);
cmd.Parameters.AddWithValue("@web", obj.Web);
cmd.ExecuteNonQuery();
}
}catch (Exception ex){}
}
I have couple of questions for the above code (1) Do I have to close connection manually? (2) Do i need to dispose Command object? (3) If exception occurs, do i have to close connection and command (4) How to enhance this code further?