Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL Server Insert query
    text
    copied!<p>I am wondering why I get an exception on the <code>SqlDataReader reader2 = theCommandInsert.ExecuteReader();</code></p> <p>This is the code I use :</p> <pre><code>var conString = ConfigurationManager.ConnectionStrings["LocalSqlServer"]; string strConnString = conString.ConnectionString; SqlConnection dbConnection = new SqlConnection(strConnString); dynamic queryString = ("INSERT INTO FOLDERS (Name) VALUES ('" + txtBoxFolderLabel.Text + "' ) "); int param = CheckBoxList2.SelectedIndex; param = param + 1; dynamic queryStringInsert = ("INSERT INTO GROUPS_FOLDERS (Folder_Id, Group_Id) VALUES(IDENT_CURRENT('Folders') , " + param + " )"); SqlCommand theCommand = new SqlCommand(queryString, dbConnection); SqlCommand theCommandInsert = new SqlCommand(queryStringInsert, dbConnection); //Connection opening and executing if (string.IsNullOrEmpty(txtBoxFolderLabel.Text) | CheckBoxList2.SelectedIndex.ToString() == null) { Response.Write("Empty fields !"); } else if (Functions.IsNumeric(txtBoxFolderLabel.Text)) { Response.Write("No numerics !"); } else { dbConnection.Open(); SqlDataReader reader = theCommand.ExecuteReader(); string folderName = txtBoxFolderLabel.Text; // Create folder System.IO.Directory.CreateDirectory("C://inetpub//wwwroot//Files//" + folderName); dbConnection.Close(); dbConnection.Open(); SqlDataReader reader2 = theCommandInsert.ExecuteReader(); dbConnection.Close(); </code></pre> <p>This is the exception I get: </p> <blockquote> <p>The INSERT statement conflicted with the FOREIGN KEY constraint "FK_GROUPS_FOLDERS_Groups". The conflict occurred in database "9B15719DF48C3E2301D7F965674A6F93_VISUAL STUDIO 2010\PROJECTS\CLIENTPORTAL\APPLICATIONUI\WEBSITE\CLIENTPORTAL\APP_DATA\DATAUI.MDF", table "dbo.Groups", column 'Id'.</p> </blockquote> <p>I did check in the database, there is no Id duplicated or something ..</p> <p>Could you help me please ?</p> <p>Cheers.</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