Salve, con il codice sottostante effettuo un inserimento:
Avrei la necessità di controllare che ciò che sto tentando di inserire non sia già presente nel db, quindi far precedere la INSERT da:codice:MySql.Data.MySqlClient.MySqlConnection objConn; MySql.Data.MySqlClient.MySqlCommand objCmd; String strConnString, strSQL; strConnString = "Server=localhost;User Id=xxxxx; Password=xxxxx; Database=xxxx_it; Pooling=false"; objConn = new MySql.Data.MySqlClient.MySqlConnection(strConnString); objConn.Open(); strSQL = "INSERT INTO tnewsletter_tracking (newsletter_id,utente_id) VALUES (" + newsletter_id + "," + utente_id + ")"; objCmd = new MySql.Data.MySqlClient.MySqlCommand(strSQL, objConn); try { objCmd.ExecuteNonQuery(); } catch (Exception ex) { Response.Write(ex.ToString()); } objCmd = null; objConn.Close(); objConn = null;
Solo se la COUNT è 0 deve effettuare la query di inserimento.codice:strSQL = "SELECT COUNT(*) FROM tnewsletter_tracking WHERE newsletter_id =" + newsletter_id + " AND utente_id = " + utente_id + "";
Come aggiungere nel codice la nuova query?
Grazie.

Rispondi quotando