Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting sql server response in ASP.net
    text
    copied!<p>I'm making a data input page in Asp.net. Entry is fine now and its got all the functionality it needs now but I'd like to have some confirmation that data has been entered.</p> <p>Initially I had this though using a bit of javascript to show a message box when the query was successful. That worked great until I changed the query insert only when the data entered does not exist in the database already.</p> <p>Here's the Asp method for data entry:</p> <pre><code> private void ExecuteInsert(string name, string type) { //Creates a new connection using the HWM string using (SqlConnection HWM = new SqlConnection(GetConnectionStringHWM())) { //Creates a sql string with parameters string sql = " IF NOT EXISTS " + " ( SELECT 1 " + " FROM tblSoftwareTitles " + " WHERE Softwarename = @SoftwareName " + " AND SoftwareSystemType = @Softwaretype " + " ) " + " BEGIN " + " INSERT tblSoftwareTitles (SoftwareName, SoftwareSystemType) " + " VALUES (@SoftwareName, @SoftwareType) " + " END; "; //Opns the connection HWM.Open(); try { //Creates a Sql command using (SqlCommand addSoftware = new SqlCommand{ CommandType = CommandType.Text, Connection = HWM, CommandTimeout = 300, CommandText = sql}) { //adds parameters to the Sql command addSoftware.Parameters.Add("@SoftwareName", SqlDbType.NVarChar, 200).Value = name; addSoftware.Parameters.Add("@SoftwareType", SqlDbType.Int).Value = type; //Executes the Sql addSoftware.ExecuteNonQuery(); } } catch (System.Data.SqlClient.SqlException ex) { string msg = "Insert Error:"; msg += ex.Message; throw new Exception(msg); } } } </code></pre> <p>and the javascript call </p> <pre><code> Alert.Show("Software instance saved!"); </code></pre> <p>this just goes to a separate file. </p> <p>Initially I had the message box script occur just at the end of the try statement. I need help in getting a repose from the server that will allow me to display a message box for when there data is fully unique and has saved or for when it isn't unique and hasn't been entered. </p> <p>I essentially need an if statement that says if the server add a record then show the message box for saved else show the message box saying the data already exists.</p> <p>Anyone have any ideas how to achieve this? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload