Click here to Skip to main content
15,889,992 members
Home / Discussions / C#
   

C#

 
QuestionDislaying 3D model in C# winform Pin
Member 1301708227-May-17 0:11
Member 1301708227-May-17 0:11 
AnswerRe: Dislaying 3D model in C# winform Pin
Dave Kreskowiak27-May-17 4:45
mveDave Kreskowiak27-May-17 4:45 
AnswerRe: Dislaying 3D model in C# winform Pin
lmoelleb28-May-17 2:21
lmoelleb28-May-17 2:21 
GeneralRe: Dislaying 3D model in C# winform Pin
Member 1301708228-May-17 21:45
Member 1301708228-May-17 21:45 
QuestionHow to retrieve image from multiple folder from SharePoint Pin
Hamizah AHMAD TALHAH24-May-17 16:08
Hamizah AHMAD TALHAH24-May-17 16:08 
QuestionRe: How to retrieve image from multiple folder from SharePoint Pin
Richard MacCutchan24-May-17 23:24
mveRichard MacCutchan24-May-17 23:24 
AnswerRe: How to retrieve image from multiple folder from SharePoint Pin
Gerry Schmitz25-May-17 5:26
mveGerry Schmitz25-May-17 5:26 
QuestionDisplay a Message for Failure or Success C# Pin
Member 1321855223-May-17 9:55
Member 1321855223-May-17 9:55 
Hi,

I am new on here and would like some help with dealing with what should be a simple task. I have a small form which is simply a data entry form for a single field (the second being a database autonumber). After running the SQL script I want either a messagebox to show that an entry already exists in the database or that the insert has been successful.

Below is my C# code.

Please can someone help as to how to achieve what I need! The above code obviously gives a successful message regardless of the real result.

Many thanks,

private void SaveButton_Click(object sender, EventArgs e)
       {
           //Validate the textbox to make sure no null or blank value can be entered
           if (contact_typeTextBox.Text == "" && contact_typeTextBox.Text == "")
           {
               errorProvider1.SetError(contact_typeTextBox, "Field must have valid text.");
           }
           else
           {
               //THE ERROR PROVIDER WILL BE CLEARED.
               errorProvider1.SetError(contact_typeTextBox, "");

               da.InsertCommand = new SqlCommand("IF NOT EXISTS(SELECT * FROM Contact_Types WHERE contact_type=@contacttype) INSERT INTO Contact_Types (contact_type) VALUES(@contacttype)", cs); //Check if the input string alread exists, if not insert it
               da.InsertCommand.Parameters.Add("@contacttype", SqlDbType.NVarChar).Value = contact_typeTextBox.Text; //Insert parameters

               cs.Open(); //Open the database connection
               MessageBox.Show("Record Successfully Saved"); //Display message box
               cs.Close(); //Close the database connection

               foreach (var conrol in Controls)
               {
                   var textbox = conrol as TextBox;
                   if (textbox != null)
                       textbox.Clear();
               }
           }
       }

AnswerRe: Display a Message for Failure or Success C# Pin
Pete O'Hanlon23-May-17 21:04
mvePete O'Hanlon23-May-17 21:04 
GeneralRe: Display a Message for Failure or Success C# Pin
Member 1321855223-May-17 23:19
Member 1321855223-May-17 23:19 
GeneralRe: Display a Message for Failure or Success C# Pin
OriginalGriff23-May-17 23:27
mveOriginalGriff23-May-17 23:27 
GeneralRe: Display a Message for Failure or Success C# Pin
MadMyche25-May-17 15:57
professionalMadMyche25-May-17 15:57 
GeneralRe: Display a Message for Failure or Success C# Pin
Pete O'Hanlon25-May-17 20:59
mvePete O'Hanlon25-May-17 20:59 
GeneralRe: Display a Message for Failure or Success C# Pin
MadMyche26-May-17 2:31
professionalMadMyche26-May-17 2:31 
GeneralRe: Display a Message for Failure or Success C# Pin
Pete O'Hanlon26-May-17 2:34
mvePete O'Hanlon26-May-17 2:34 
AnswerRe: Display a Message for Failure or Success C# Pin
Richard MacCutchan23-May-17 21:16
mveRichard MacCutchan23-May-17 21:16 
Questionc# data table filter Pin
Member 1298110422-May-17 19:51
Member 1298110422-May-17 19:51 
AnswerRe: c# data table filter Pin
OriginalGriff22-May-17 20:35
mveOriginalGriff22-May-17 20:35 
AnswerRe: c# data table filter Pin
Pete O'Hanlon22-May-17 23:45
mvePete O'Hanlon22-May-17 23:45 
GeneralRe: c# data table filter Pin
Chris Quinn23-May-17 0:24
Chris Quinn23-May-17 0:24 
GeneralRe: c# data table filter Pin
Pete O'Hanlon23-May-17 1:17
mvePete O'Hanlon23-May-17 1:17 
Questionhow to achieve cell_doubleclick event to be fired on gridview Pin
Mayank Kumar22-May-17 18:45
Mayank Kumar22-May-17 18:45 
AnswerRe: how to achieve cell_doubleclick event to be fired on gridview Pin
Richard MacCutchan22-May-17 21:19
mveRichard MacCutchan22-May-17 21:19 
GeneralRe: how to achieve cell_doubleclick event to be fired on gridview Pin
Mayank Kumar22-May-17 22:43
Mayank Kumar22-May-17 22:43 
GeneralRe: how to achieve cell_doubleclick event to be fired on gridview Pin
Richard MacCutchan22-May-17 22:58
mveRichard MacCutchan22-May-17 22:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.