To Display An Alert Message While Inserting A Duplicate Record
I am duplicating a record from my asp.net page in to the database. When i click on save I am getting the following error message
Violation of PRIMARY KEY constraint 'PK_clientinfo'. Cannot insert duplicate key in object 'clientinfo'. The statement has been terminated.
The above message i am getting since i have tried to duplicate the clientname field of my table which is set as the primary key.
What i want is instead of this message in the browser i need to display an alert saying "the clientname entered already exists" by checking the value from the database.
Here is my code. pls modify it to achieve the said problem
if(Page.IsValid==true)
{
conn.Open();
SqlCommand cmd = new SqlCommand("insert into clientinfo (client_name, address) values ('"+txtclientname.Text+"', '"+txtaddress.Text+"')", conn);
cmd.ExecuteNonQuery();
conn.Close();
BindData();
txtclear();
System.Web.HttpContext.Current.Response.Write("<script>alert('New Record Added!');</script>");
Response.Redirect("Clientinfo.aspx");
}
View Complete Forum Thread with Replies
Related Forum Messages:
Inserting Of Duplicate Records Error Message
I would like to know what options I have with regards to trapping a duplicate record before it tries to post to a SQL database. I have set the column to unique in SQL. But when I try to use ASP and post a duplicate record I get a system error. I would like to just create a referential error to notify the user that they cannot post a duplicate record please try again. Any help would be greatly appreciated. RT
View Replies !
SSRS Alert/message Box
I using SQL Reporting 2005 acording our specification we have to display alert if the search criteria is not able to retrieve any value..So can anyone help me to display simple alert ,message box on loading of Report file
View Replies !
Sending A Alert Message Using Send Mail Task
i have developed a pakage which populates a two different tables with reference to the xml files added to a folder which is watched by a security WMI task.it is governed by a sequence container which contains three for each loop container for working on the different files.i have different event handlers set up inside for each loop container tasks which contains , data flow task, execute sql task, and moving the processed file to the desired destination.i want to set up a send mail task on the package level using event handler on error, where i have set up a task for looging the error to the error table , i have tried to collect all the error messages in a array list variable . and trying to use that variable a s a message source. i could not under stand if i set the propogation variable in the sequence container as false than will the onpost execute event will fire the onpostexecute event handler in the package level.if show how can i send only one email for all the errors of package with error looging.
View Replies !
Deadlock Alert (message ID 1205) No Longer Able To Be Logged In 2005
Hi all, In SQL Server 2000 you could run the piece of code below, to enable the logging of a deadlock in the SQL Server error log. Which could then be used to fire an alert, and then kick of an Agent job to send an SMTP email alert. Exec sp_altermessage 1205, 'WITH_LOG', 'true' The error message logged was a nice simple one liner, like this: Transaction (Process ID 57) was deadlocked on lock resources with another process and has been chosen as the deadlock victim. Rerun the transaction. Now I work for a managed SQL Server company, and a large number of our clients used our alerting for deadlocking to tune their applications, or at a minimum to show them when something was wrong with the database due to sudden rise in the number of deadlocks. However, in SQL Server 2005, the functionality for the sp_alertmessage procedure has been changed so that you can't update any message id less than 50,000. Which comes inline with the secure engine that Microsoft have designed. But this now means you can no longer enable the logging for deadlock message ID 1205. Which in turn means no alerting can be enabled. You can still log information by enabling the necessary trace flags, however that logs very verbose information about the deadlocking chain, which in turn can quickly blow the size of the error logs out. What I would love to see is this functionality returned in SQL Server 2008, or at least an alternative so that only minimum information is logged initially for a deadlock, and alerting can be setup. Also, for those of you who have read through the 2005 BOL, about deadlocking, although it states the following in the section on deadlocking: "...The 1205 deadlock victim error records information about the threads and resources involved in a deadlock in the error log.€? This isn't the case, unless you enable some trace flags, which as mentioned will give you a whole lot of information, which although is valuable, isn't ideal if you're wanting day to day deadlock tracking. Does anyone have any thoughts on this? Have you struck this as well? Do you think this should be something that shouldn't have been removed from 2000? Cheers, Reece.
View Replies !
TOUGH INSERT: Copy Sale Record/Line Items For &"Duplicate&" Record
I have a client who needs to copy an existing sale. The problem isthe Sale is made up of three tables: Sale, SaleEquipment, SaleParts.Each sale can have multiple pieces of equipment with correspondingparts, or parts without equipment. My problem in copying is when I goto copy the parts, how do I get the NEW sale equipment ids updatedcorrectly on their corresponding parts?I can provide more information if necessary.Thank you!!Maria
View Replies !
Inserting Duplicate Data
This is probably a silly question to most of you, but I'm in the processof splitting off years from a large DB to several smaller ones. Some ofthe existing smaller DBs already have most of the data for theirrespective years. But some of the same data is also on the source DB.If I simply do an insert keying on the year column, and a row beinginserted from the source DB already exists in the target DB, will aduplicate row be created?And if so, how can I avoid that?Thanks,John Steen*** Sent via Developersdex http://www.developersdex.com ***Don't just participate in USENET...get rewarded for it!
View Replies !
How Can I Prevent From Inserting Duplicate Data?
I have a table storing only 2 FKs, let's say PID, MID Is there any way that I can check distinct data before row is added to this table? For example, current data is PID MID------------100 2001100 2005101 3002102 1009102 7523102 2449 If my query is about to insert PID 100, MID 2001, since it's existing data, i don't want to add it. Can I use trigger to solve this issue? Thanks.
View Replies !
Stop Inserting Duplicate Entries
Hi I am trying to insert entries in a table which has a composite primary key and i am inserting it on UID basis. INSERT INTO TABLE_B (TABLE_B_UID,NUM_MIN, NUM_MAX,BIN, REGN_CD, PROD_CD, CARD) (SELECT UID,LEFT(NUM_MIN,16),LEFT(NUM_MAX,16),BIN, REGN_CD, PROD_CD, CARD FROM TABLE_A WHERE UID NOT IN (SELECT TABLE_B_UID FROM TABLE B)) When i insert it tries to insert a duplicate entries and gives me an error. Since I am new to SQL SERVER 2000 i need some help. I tried IF NOT EXISTS, EXCEPT but i guess i am wrong at the syntax. Can anybody help me out?
View Replies !
Preventing The Message 'Duplicate Key Was Ignored'
My problem is that the 'INSERT INTO' query that sends the records to thetable is dynamically compiled in VBA and and the target table has a twocolumn primary key. I have made a number of attempts at getting 'WHERENOT EXISTS' to cure the problem but so far without success and previouspostings have resulted in advice to create an 'ignore duplicates' index.This solved the problem in asmuch as it allowed the SQL to insert the records that did not alreadyexist but resulted in the message appearing every time the user ran thethe query. Whilst this is not a major problem it is vaguely irritatingand I would like to find a way to stop it happening. I suspect that thesolution may involve using the @@ERROR command but I am not sure of thesyntax.RegardsColin*** Sent via Developersdex http://www.developersdex.com ***
View Replies !
Searching A Column For A Value To Avoid Inserting A Duplicate Value
Hi there, newbie here. I'm building a web application that allows for tagging of items, using ASP.NET 2.0, C# and SQL Server. I have my USERS, ITEMS and TAGS separated out into three tables, with an intersection table to connect them. Imagine a user has found an item they are interested in and is about to tag it. They type their tag into a textbox and hit Enter. Here's what I want to do: I want to search the TagText column in my TAGS table, to see if the chosen tag is already in the table. If it is, the existing entry will be used in the new relationship the user is creating. Thus I avoid inserting a duplicate value in this column and save space. If the value is not already in the column, a new entry will be created. Here's where I'm up to: I can type a tag into a textbox and then feed it to a query, which returns any matches to a GridView control. Now I'm stuck... I imagine I have to use "if else" scenario, but I'm unsure of the code I'll have to use. I also think that maybe ADO.NET could help me here, but I have not yet delved into this. Can anyone give me a few pointers to help me along? Cheers!
View Replies !
Duplicate Record
Dear All, I need to identify duplicate records in a table. TableA [ id, firstname, surname] I’d like to see records that may be duplicates, meaning both firstname and surname are the same and would like to know how many times they appear in the table I’m not sure how to write this query, can someone help? Thanks in advance!
View Replies !
Duplicate Record
Hi guys how do you hide duplicate records, how would I do a select statement for that In (SELECT [AccountNo] FROM [2006_CheckHistory] As Tmp GROUP BY [AccountNo] HAVING Count(*)>1 ) I have about had it with this database I have been asked to make a report out of
View Replies !
Stored Procedure Inserting Duplicate Records Randomly
I have a web app that calculates tax filing status and then stores data about the person. Facts The insert is done through a stored procedure. All the sites that this program is being used are connecting through a VPN so this is not an external site. The duplicate records are coming from multiple sites (I am capturing there IP address). I am getting a duplicate about 3 or 4 times a day out of maybe 300 record inserts. Any help would be greatly appreciated. There are many sqlcmdInsert.Parameters("@item").Value = cnTaxInTake.Open() sqlcmdInsert.ExecuteNonQuery() cnTaxInTake.Close() And that is it.
View Replies !
Display A Message In Store Procedure
helo all..., this is my store procedure. but it can not display message. my friend said it must use output code. can someone add output code to my store procedure, so it can display message?ALTER PROCEDURE [bank].[dbo].[pay]( @no_bill INT, @no_order int, @totalcost money, @message varchar(100) -- make it output parameter in your stored procedure)ASBEGIN TRANSACTION DECLARE @balance AS moneyselect @balance = balancefrom bank.dbo.billwhere no_bill = @no_billselect @totalcost = totalcostfrom games.dbo.totalcostwhere no_order = @no_orderif (@balance > @totalcost)beginset @balance = @balance - @totalcostUPDATE bank.dbo.bill SET [balance] = @balance WHERE [no_bill] = @no_bill-- set @message = 'your have enough balance'endelsebeginset @message = 'sorry, your balance not enough'endCOMMIT TRANSACTIONset nocount off pls.., thx
View Replies !
Display Error Message On Screen If No Value
I have a screen set up in another software package which accepts 2 values on a form - 'Number1' and 'Number2' I need to check that at least a value is entered in one or both ... If both values are 0 (set on dispaly of the form )then I need to throw an error message to that effect on screen .... (The Sql script is triggered after the form data has been entered) Can anyone help me with the SQL script please to check the values ???
View Replies !
Error Message On Attempted Duplicate Insert
Hi All, I have a web form that inserts information into two tables in sql 2005 database on a submit button click. I have a unique key on the tables preventing duplicate information which works fine. The problem I have is that at the minute if a users tries to insert a duplicate row they just get the built in sql error message. Is there a way I can validate the information before if goes into the database and display perhaps a label telling the user of their error or is there a way I can customize the build in sql error message? I've had a search on various forums and sites and can't find any info that would help me. Thanks in advance Dave
View Replies !
Display Each Of The Record
I want to know how to display only each of it where in my database for example the ProductItem got a lot of value of '1000' in it. i only want it to display once. ProductItem | Name 1000 | ABC 1000 | DEF 1000 | HIJ 2000 | KLM 3000 | NOP I want in my dropdownlistbox only display 1000, 2000, 3000. I using the 'Select ProductItem from Product' for sure it will display 1000,1000,1000,2000,3000. So to filter it. Thanks
View Replies !
Display Record Of The Day
Hi Guys, How do I display an item in a day? This is a featured product of the day. This will change everyday. I can do this in classic ASP but not in stored procedure. Table: This is just to give you an idea of the table ID | ProductName | DatePosted ---------------------------------------- 1 | item1 | 5/1/2008 2 | item2 | 1/2/2008 3 | item3 | 6/2/2007 and so on... Can someone please help me? Thanks in advanced.
View Replies !
Duplicate Inserted Record
Hi EverybodyThis Code duplicate the record in the database, can somebody help me understand why that happen. Thanks a LOT CompanyName: <asp:textbox id="txtCompanyName" runat="server" /><br />Phone:<asp:textbox id="txtPhone" runat="server" /><br /><br /><asp:button id="btnSubmit" runat="server" text="Submit" onclick="btnSubmit_Click" /><asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:dsn %>" insertcommand="INSERT INTO [items] ([smId], [iTitleSP]) VALUES (@CompanyName, @Phone)" selectcommand="SELECT * FROM [items]"> <insertparameters> <asp:controlparameter controlid="txtCompanyName" name="CompanyName" /> <asp:controlparameter controlid="txtPhone" name="Phone" /> </insertparameters></asp:sqldatasource> VBPartial Class Default2 Inherits System.Web.UI.Page Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click SqlDataSource1.Insert() End SubEnd Class ----------------------------------------------Yes is an Identity the Primary Key of the Table items
View Replies !
Duplicate Record Trigger
This is part of my trigger on table T1. I am trying to check if the records inserted to T1 is available in myDB.dbo.myTable or not (destination table). If it is available rollback T1. It does not do that although I insert the same records twice. -- duplicate record check SET @step = 'Duplicate record' IF EXISTS ( SELECT i.myID, i.Type FROM INSERTED i INNER JOIN myDB.dbo.myTable c ON i.myID = c.myID GROUP BY i.myID, i.Type HAVING (COUNT(*) > 1) AND (i.Type = 'In') ) BEGIN ROLLBACK transaction RAISERROR('Error: step: %s. rollback is done.', 16, 1, @step) Return END What is problem?
View Replies !
Duplicate Record Problem
I am working on a web application that utilizes a sql server database. One of the tables is a large text file that is imported through a DTS package from a Unix server. For whatever reason, the Unix box dumps quite a few duplicate records in the nightly run and these are in turn pulled into the table. I need to get rid of these duplicates, but can't seem to get a workable solution. the query that is needed to get the records is:SELECT tblAppointments.PatientID, tblPTDEMO2.MRNumber, tblAppointments.PatientFirstName, tblAppointments.PatientLastName, tblAppointments.PatientDOB, tblAppointments.PatientSex, tblAppointments.NewPatient, tblAppointments.HomePhone, tblAppointments.WorkPhone, tblAppointments.Insurance1, tblPTDEMO2.Ins1CertNmbr, tblAppointments.Insurance2, tblPTDEMO2.Ins2CertNmbr, tblAppointments.Insurance3, tblPTDEMO2.Ins3CertNmbr, tblAppointments.ApptDate, tblAppointments.ApptTimeFROM tblAppointments CROSS JOIN tblPTDEMO2WHERE (tblAppointments.PatientID = tblPTDEMO2.MRNumber)AND tblAppointments.Insurance1 = 'MED'AND tblAppointments.ApptTypeID <> 'MTG'AND tblAppointments.ApptTypeID <> 'PNV'AND DateDiff("dd", ApptDate, GetDate()) = 0Order By tblAppointments.ApptDateMy first thought was to try to get a Select DISTINCT to work, but couldn't figure out how to do this with the query. My next thought was to try to set up constraints on the table, but, since there are duplicates, the DTS package fails. I assume there is a way to set up the transformations in a way to get this to work, but I'm not enough of an expert with SQL Server to figure this out on my own. I guess the other way to do this is to write some small script or application to do this, but I suspect there must be an easier way for those who know what they are doing. Any help on this topic would be greatly appreciated. Thanks.
View Replies !
Duplicate Record Question
In order to check that a new users ID does not already exist in the database I thought it would be a good idea to put the Insert into a Try Catch statement so that I can test for the duplicate record exception and inform the user accordingly. I was also trying to avoid querying the data base before executing the Insert. The problem is what to actually test for. When the code throws the exception it is a big long string . . "Violation of PRIMARY KEY constraint 'PK_Users_2__51'. Cannot insert duplicate key in object 'Users'" I just thought that there has to be something simplar to test for than comparing the exception to the above string. Can anyone tell me of a better way of doing this ? (by the way I am only using Web Matrix and MSDE in case it matters) Mark
View Replies !
Update A Duplicate Record
Hi everybody, I have 2 fields in a table. Table Name--- StudentDetail Name Address Saju Kerala Balaji Bangalore Raj Kumar Tamilnadu Saju Kerala I want to Update one of the duplicate row as I don't have any unique id column. So can anybody update one of the the duplicate record without using any id or altering any column. I am waiting for your reply................. Regards, Saju S.V
View Replies !
Extracting Duplicate Record On The Same Id
Hi everybody i need help on on a query on how i can extract this... with the following table below.. id pub 1 a 1 b 2 c 2 c I need to extract only the id and pub where pub has more than one with the same id... in the case of the above the result would be id pub 2 c 2 c thanks
View Replies !
Duplicate Record Problem
So I'm working on updating and normalizing an old database, and I have some duplicate records that I can't seem to get rid of. Every column is identical, right down to what is supposed to be the key. I can't right a delete query to just isolate one row, and I can't delete (or even udpate) any row in management studio. Any thoughts on how to remove the extra rows? There is a field that's supposed to be unique, so I can write a simple query to get all of the problem rows. The only thing is that they come back in pairs.
View Replies !
Eliminate Duplicate Record(s)?
Hey Again, I've been making great progress but I've hit another road block which a newbie intern like myself can't surpass. What's worse is the fact that no one is in the office today! Maybe someone can point me in the right direction with this SQL: SELECT r.[requestID] ,r.[requserID] ,r.[departmentID] ,CONVERT(CHAR(8),r.[submitDate],10)AS submitDate ,CONVERT(CHAR(8),r.[dueDate],10)AS dueDate ,CONVERT(CHAR(8),r.[revisedDueDate],10) AS revisedDueDate ,r.[reqStatus] ,r.[completedDate] ,d.[departmentName] ,s.[statusName] ,u.lastName + ', ' + u.firstName AS submittedBy ,ra.userID FROMtblUserDepartment ud INNER JOIN tblRequest rON ud.departmentID = r.departmentID INNER JOIN tblDepartment dON r.departmentID = d.departmentID INNER JOIN tblStatus sON r.reqStatus = s.statusID INNER JOIN tblUser uON r.requserID = u.userID LEFT JOIN tblRequestAssignee ra ON r.requestID = ra.requestID WHEREud.userID= @userID This works great except for one thing. In tblRequestAssignee, you have 1 primary assignee and can have several other assignees (that are not primary). This is denoted by a bit field "isPrimaryAssignee" in tblRequestAssignee. When I run the query, I see every request I want to but it duplicates requests with more than one assignee. What I'm trying to do is make only the primaryAssignee display if there is one. If there's not, then null is displayed (which is already happening). Like I said, the query is mostly working right except for this duplicate record that displays when there's 2 assignees. Any help would once again be greatly appreciated.
View Replies !
Delete Duplicate Record
Hi , How can i delete the duplicate record from a table use Northwind create table Emp (Ecode char(2), Ename char(10)) Insert into Emp(Ecode, Ename) values('A1','A') Insert into Emp(Ecode, Ename) values('A1','A') Insert into Emp(Ecode, Ename) values('A2','B') Insert into Emp(Ecode, Ename) values('A2','B') Insert into Emp(Ecode, Ename) values('A3','C') Insert into Emp(Ecode, Ename) values('A3','C') Insert into Emp(Ecode, Ename) values('A4','D') Insert into Emp(Ecode, Ename) values('A4','D') select * from emp order by Ecode Thanks ASM
View Replies !
How To Display SQL Server Error Message On Web Form
I have following Stored Procedure ... How do I display Error Message Return by Stored Procedure ?? CREATE PROCEDURE [AddNewUserDetails] ( @UserName nvarchar(30), @Passcode nvarchar(10), @FName nvarchar(30), @LName nvarchar(30), @UserRoleID int, @AccStatus nvarchar(50) ) AS IF EXISTS ( SELECT 'TRUE' FROM UserDetails where logname = @UserName) BEGIN -- Notify user about duplicate username SELECT 'Username already exists' END ELSE BEGIN -- Username doesn't exists in database, add it and notify admin SELECT 'Record Added' DECLARE @userid int SELECT @userid = MAX(userid) + 1 FROM UserDetails INSERT INTO UserDetails VALUES (@userid, @UserName, @Passcode, @FName, @LName, @UserRoleID, @AccStatus) END GO Here is the code for Calling Stored Procedure public string AddNewUserDetails(string UserName, string Passcode, string FName, string LName, int UserRoleID, string AccStatus) { // Create Instance of Connection and Command Object SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]); SqlCommand myCommand = new SqlCommand("AddNewUserDetails", myConnection); // Mark the Command as a SPROC myCommand.CommandType = CommandType.StoredProcedure; // Add Parameters to SPROC SqlParameter parameterUserName = new SqlParameter("@UserName", SqlDbType.NVarChar, 50); parameterUserName.Value = UserName; myCommand.Parameters.Add(parameterUserName); SqlParameter parameterPasscode = new SqlParameter("@Passcode", SqlDbType.NVarChar, 50); parameterPasscode.Value = Passcode; myCommand.Parameters.Add(parameterPasscode); SqlParameter parameterFName = new SqlParameter("@FName", SqlDbType.NVarChar, 50); parameterFName.Value = FName; myCommand.Parameters.Add(parameterFName); SqlParameter parameterLName = new SqlParameter("@LName", SqlDbType.NVarChar, 50); parameterLName.Value = LName; myCommand.Parameters.Add(parameterLName); SqlParameter parameterUserRoleID = new SqlParameter("@UserRoleID", SqlDbType.SmallInt, 2); parameterUserRoleID.Value = UserRoleID; myCommand.Parameters.Add(parameterUserRoleID); SqlParameter parameterAccStatus = new SqlParameter("@AccStatus", SqlDbType.NVarChar, 50); parameterAccStatus.Value = AccStatus; myCommand.Parameters.Add(parameterAccStatus); try { myConnection.Open(); myCommand.ExecuteNonQuery(); } catch (SqlException ex) { Console.WriteLine(ex.Message.ToString()); return ("Error Adding New User Details"); } finally { myConnection.Close(); } return ("New User Added Successfully"); }
View Replies !
Check If Database Is Down, Display Custom Message
Hi, I have been using SSRS for creating and getting data from the Oracle databases. I want to display customer error message "Database is down" if the oracle database is down. Is there anyway to check if database is down and display custom error message?
View Replies !
Display A Message On Report Manager Homepage
Afternoon everyone, Just a quickie. Besides creating a new folder and using the folder description, is there a way to display a message on the report manager home page? I'd like to display a quick message in large bold font about how users can get Reporting Services Support. Thanks, Paul
View Replies !
How To Get The 2nd The 2nd Record AND DISPLAY IN SINGLE ROW ?
Can you please assist me on how to get the 2nd record in case there are3 or more records of an employee, the query below gets the MAX and MINBasicSalary. However, my MIN Basic Salary is wrong because I should getthe Basic Salary Prior to the 1st Record (DESC)in case there are 3 ormore records and not the last Basic Salary of the Last Record.How to GET the 2nd Row of Record in Case that There are 3 or morerecords IN A SINGLE ROW ???---------------------------------------------------------------------------*-----This query gets the Max and Min Basic Salary on a certain Date Range.In case there are 5 records of an employee on certain date range howcan I get the record before the Max and would reflect as my OLDBASIC,if I use TOP2 DESC it will display 2 records. I only need one recordwhich should be the Basic Salary before the 1st record on a DESC order.Please add the solution to my 2nd Select Statement which get theOLDBASIC salary Thanks ...SELECT TOP 100 PERCENT E.EmployeeNo, E.LastName, E.FirstName,E.SectionCode, E.Department, E.DateHired, E.Remarks,(SELECT TOP 1 ([BasicSalary])FROM empsalaries AS T14WHERE T14.employeeno = E.employeeno AND startdate BETWEEN @FromDate AND@ToDateORDER BY startdate DESC) AS NEWBASIC,******************************* BELOW I SHOULD ALWAYS GET THE BASICSALARY PRIOR TO THE 1ST RECORD AND IN A SINGLE ROW ???(SELECT TOP 1 ([BasicSalary]) (FROM empsalaries AS T14WHERE T14.employeeno = E.employeeno AND startdate BETWEEN @FromDate AND@ToDateORDER BY startdate ASC) AS OLDBASICFROM dbo.Employees EWHERE CONVERT(VARCHAR(10),E.DateHired, 101) BETWEEN @FromDate AND@ToDate ORDER BY E.LastName
View Replies !
Duplicate Record Inserted. Weird.........
1 Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click 2 Dim sqlStr As String 3 Dim sqlStr2 As String 4 Dim myConnection As MySqlConnection = Nothing 5 Dim myCommand As MySqlCommand = Nothing 6 Dim myConnection2 As MySqlConnection = Nothing 7 Dim myCommand2 As MySqlCommand = Nothing 8 Dim myReader As MySqlDataReader = Nothing 9 Dim IC As String 10 11 IC = txtIC1.Text + "-" + txtIC2.Text + "-" + txtIC3.Text 12 13 14 Try 15 sqlStr2 = "SELECT * FROM User WHERE uLogin='" & txtUserName.Text.Trim() & "'" 16 17 ' Connection 18 myConnection2 = New MySqlConnection(ConfigurationManager.ConnectionStrings("dbConnection").ToString()) 19 myConnection2.Open() 20 ' Command 21 myCommand2 = New MySqlCommand(sqlStr2, myConnection2) 22 ' Reader 23 myReader = myCommand2.ExecuteReader() 24 Catch ex As Exception 25 ' Exception Error Here 26 Response.Write(Err.Number & " - " & Err.Description) 27 28 End Try 29 ' Checking 30 If myReader.Read() Then 31 32 33 Label2.Text = "Username already exist. Please choose another username" 34 Label3.Text = "*" 35 36 Else 37 38 Try 39 40 41 sqlStr = "INSERT INTO userapplication(uaName,uaIC,) VALUE (?uName,?uIC )" 42 43 44 45 ' Connection 46 myConnection = New MySqlConnection(ConfigurationManager.ConnectionStrings("dbConnection").ToString()) 47 myConnection.Open() 48 'Command 49 myCommand = New MySqlCommand(sqlStr, myConnection) 50 51 myCommand.Parameters.AddWithValue("?uName", txtName.Text) 52 myCommand.Parameters.AddWithValue("?uIC", IC) 53 54 55 myCommand.ExecuteNonQuery() 56 myConnection.Close() 57 Response.Redirect("Register.aspx", False) 58 59 Catch ex As Exception 60 ' Exception Error Here 61 Response.Write(Err.Number & " - " & Err.Description) 62 Finally 63 ' Clean Up 64 If Not IsNothing(myCommand) Then 65 myCommand.Dispose() 66 End If 67 ' 68 If Not IsNothing(myConnection) Then 69 If myConnection.State = Data.ConnectionState.Open Then myConnection.Close() 70 myConnection.Dispose() 71 End If 72 End Try 73 74 75 End If 76 77 End Sub 78 79 above is my code for the user registration page.the code that i bold,which with number 55,56 and 57,are where the problem occur. when it run,it run 55, then 57,then back to 55, then 57 again means that my db hav duplicate record being insert anyone know how to solve this problem?
View Replies !
Simple Duplicate Record Question
I have a table with 2 columns, col1 is unique, col2 is not. col1 is numeric col2 is varchar. Here is the problem, col2 will have duplicate values, I need the largest numeric value from col1 with unique value from col2. Thanx for any help.
View Replies !
Help Selecting Duplicate Record Details
I have the following query I am using to identify duplicate records in one of my database tables: Code: SELECT memberID, COUNT(memberID) AS NumOccurrences FROM ChapterMembers GROUP BY memberID HAVING ( COUNT(memberID) > 1 ) Executing the above proc returns 4079 records... Now, I would also like to know the ChapterID for each member with a duplicate record. ChapterID is also stored in the ChapterMembers Table... I tried running the following procedure: Code: SELECT memberID, COUNT(memberID) AS NumOccurrences, chapterID FROM ChapterMembers GROUP BY memberID, chapterID HAVING ( COUNT(memberID) > 1 ) But zero results are returned ... The ultimate goal here is to identify duplicate records where one of their chapterID's = '81017' and to delete that record from the database. Anyone have any ideas what I am doing wrong? Also, any suggestions for removing the records would be appreciated. Thanks, Jandrews
View Replies !
Fetch Returning Duplicate Last Record
Ok, this thing is returning the last record twice. If I have only one record it returns it twice, multiple records gives me the last one twice. I am sure some dumb pilot error is involved, HELP! Thanks in advance, Larry ALTER FUNCTION dbo.TestFoodDisLikes ( @ResidentID int ) RETURNS varchar(250) AS BEGIN DECLARE @RDLike varchar(50) DECLARE @RDLikeList varchar(250) BEGIN SELECT @RDLikeList = '' DECLARE RDLike_cursor CURSOR LOCAL SCROLL STATIC FOR SELECT FoodItem FROM tblFoodDislikes WHERE (ResidentID = @ResidentID) AND (Breakfast = 'True') OPEN RDLike_cursor FETCH NEXT FROM RDLike_cursor INTO @RDLike SELECT @RDLikeList = @RDLike WHILE @@FETCH_STATUS = 0 BEGIN FETCH NEXT FROM RDLike_cursor INTO @RDLike SELECT @RDLikeList = @RDLikeList + ', ' + @RDLike END CLOSE RDLike_cursor DEALLOCATE RDLike_cursor END RETURN @RDLikeList END
View Replies !
Deleting The Duplicate Record From Table
Hi , i am using sql server 2005. i have one table where i need to find records that have same citycode and hospitalcode and doctorcode then delete the record keeping only one record of them my problem is table structure have idendtity column which is unique. that is m table structure is something like recid citycode hospcode doctorcode otherdesp 1 0001 hp001 d0001 ... 2 0002 hp002 d0002 ... 3 0001 hp001 d0001 ... 4 0002 hp002 d0002 ... please suggest thank you
View Replies !
Inserting 1 Row And Getting A Message That Two Rows Were Inserted.
Why does this code tell me that I inserted 2 rows when I really only inserted one? I am using SQL server 2005 Express. I can open up the table and there is only one record in it. Dim InsertSQL As String = "INSERT INTO dbCG_Disposition ( BouleID, UserName, CG_PFLocation ) VALUES ( @BouleID, @UserName, @CG_PFLocation )"Dim Status As Label = lblStatus Dim ConnectionString As String = WebConfigurationManager.ConnectionStrings("HTALNBulk").ConnectionString Dim con As New SqlConnection(ConnectionString) Dim cmd As New SqlCommand(InsertSQL, con) cmd.Parameters.AddWithValue("BouleID", BouleID) cmd.Parameters.AddWithValue("UserName", UserID) cmd.Parameters.AddWithValue("CG_PFLocation", CG_PFLocation) Dim added As Integer = 0 Try con.Open() added = cmd.ExecuteNonQuery() Status.Text &= added.ToString() & " records inserted into CG Process Flow Inventory, Located in Boule_Storage." Catch ex As Exception Status.Text &= "Error adding to inventory. " Status.Text &= ex.Message.ToString() Finally con.Close() End Try Anyone have any ideas? Thanks
View Replies !
Inserting A New Record
I want to insert a new record into my db in asp.net. Im programming in vb and using an sql server database. i know this is a begginers question but that's exactly what i am. Thanks in advance
View Replies !
Inserting A Record!!
Hi Everyone, I want to do something like this. ************************************************** ************************ insert into mytable(field1,field3) values ('amits', (select field1 from trial where field2 = 2)) ************************************************** ************************* (this gives an error) is there a way to do this or something of this sort Thanks, Mohit
View Replies !
Display 2 Record Each From 2 Table In Datagrid
This is my case. I want in my datagrid to display first record from table A and second record from table B. This is because i need to display a price in the column where it will have current price and history price, therefore the first row will be current price and second row will be history price. This is the output that i trying to do. Item | Price -------|--------- A | 2.50 --------> Table A A | 1.50 --------> Table B Please let me know if my explanation is not details enough. Thanks
View Replies !
|