DataSource Controls :: SQL Statement / Don't Have Any Unique Identifier?
Mar 11, 2010
I am just wondering how do I get the very last row of a join statement if I don't have any unique identifier... as in row_number field?Is there a way of creating a dummy column on my SQL statement to hold the record numbers of all records ..[1 to n] etc ???Id like to know how to do this and then I can get the MAX record number.Im using SQL server 2005 so the last() function doesn't work.
I'm using Visual Web Developer Express 2008 and SQL Management Studio Express 2005. I need to link 2 tables to either present in a Master/Detail or GridView/Form view.The goal is to allow the user to view time card information from the AS400 (read only) and then enter any corrections into a SQL table. My problem is in trying to connect the two tables.I've asked the AS400 administrator to add a unique identifier field to the table (HAPOINT), but he says he can't. I've tried to concatenate a field within Visual Web Developer's Query Builder but keep getting errors.Table 1 - exists in AS400, is non-permanent (cleared every 3 months) and can't be modifiedEmpl ID WO Date In Time In Date Out Time Out Table 2 - exists in SQL Server, newly created for this project (no data yet, so can be modified)Rev ID Empl ID Date (of revision entry) X (Revise - y/n) Revised Time In Revised Time Out I tried finding a solution through the SQL Forum, but haven't gotten a solution, so I'm posting here. There are additional details at that post:http://forums.asp.net/p/1516929/3658517.aspx#3658517Can anyone tell me how to concatenate "Empl ID /WO / Date In / Time In" from Table 1 to produce a unique identifier that I can then use in Table 2, thus providing the link between the two tables? Or, is there another way?
I realize that user names are unique, but is there another identifier associated with the username? If there is, how do I find out what it is for the user who is currently logged in?
I'm creating a website with sql server db (built in membership database). I design it best possible. Im reluctant to use text fields as identifiers, but this is pretty much my first sql server db.
1. The user registers himself, at the same time registering his company/organisation. I dont think many of them will have the need to register themselves to other companys (N:N) but you never know (anyway not a main concern at the moment).
2. This user becomes a superuser (level1), with the ability to register other users to the same company (level2 users). Finally level1 can register level3 users to the same company.
So you see the identifier will be everywhere in the sql commands. There are quite a few N:N relations as well, which I guess slows it down even more. The selections typically retrieves a few hundred to a few thousand posts, but like I said, many will be in N:N relations.
I'm going to write my own Authentication module and I need a unique identifier base on users requests header , I think [(user IP)+(user Agent)] can be reasonable but I know it's not completely safe do you know any other options or methods?
Code: <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SQL2008R2_799650_xnacsConnectionString %>" SelectCommand="SELECT [ArticleTitle], [articlehtml], [submittedby], [datesubmitted] FROM [Articles] where articleid ='@id'"> </asp:SqlDataSource>
and code behind is taking a url param (guid) and passing it to the select above it looks like this:
Code: protected void Page_Load(object sender, EventArgs e) { string id = Request["article"]; as simple as that, the problem is the page falls over saying it cannot convert string to Unique identifier, I'm new to asp.net but not c# so there are a few bits i'm trying to get my head round..
Right now I am creating this session with the session key "PhonePart" which is also the name of object I am passing in as a parameter in first method. In subsequent methods, I use the the same name to retreive and clear session value. My problem is, this approach works fine If I instantiate a single object of the class where these methods are defined and using that object call the methods, but when I create another instance of the same class and calls for instance method AddToSession and pass that instance, it overwrites the session value stored by the first instance of the class as the session key is the same that is "PhonePart".
Considering this scenario, is it possible that I somehow grab the name of the object as string in the calling method say "AddToSession" and create a session with that name? If Yes, then I can do the same in subsequent methods and retreive session value and also clear the session specific to that instance name without affecting the other session values stored by other instances.
i have a web application with form identification agains ActiveDirectory. The user is added to the aspnetdb and then we add his roles and profile.heres my question. If you have a user with "abcdef" for his sAMAccountName and then this user quit the job and someone else came in and we give him the SAME sAMAccountName, how aspnet will react? i guest it will see that the sAMAccountName already exist in the aspnetdb and will use it? if its true, then i will have a problem that the new user will inherit the old user access and profile!how can i solve this? i know theres a objectGUID attribute in AD that i can use but how can i use it with aspnetdb?
When the user clicks the edit button I want to pass the unique identifier from the item in the list to the parameter string so I can retrieve it in the edit page. how to retrieve the ID from the selected item?
I need to generate a Unique Reference number that has 7 digits.
It should be formatted in the following way:
1st: B (Ball), G (Gift), C (Cat)
2nd: represents year of booking A(2010), B(2011),C(2012), etc
3rd: represents the month of booking J(Jan),F(Feb),M(Mar),A(Apr),Y(May), U(Jun), L(Jul),G(Aug), S(Sep),O(Oct),N(Nov),D(Dec)
4th: days of booking A(1st) - Z(26th), 1(27th) - 5(31st)
5,6,7th: These are counters for the number issues each day. Each can be A-Z,0-9 giving a total of 46,656 combinations. So 0 is first, then 1, 2, 3, 4, 5, 6, 7, 8, 9, A-Z, then 00 to 0Z, then 10 to 1Z, then 20 to 2Z, etc
Now , the 1st Digit is a Character that I generate based on a condition and that shouldn't be a problem.
there is a statement like " select t.f1, (select ta.f2 from ta where t.fk1=ta.fk1) from t inner join ta on t.fk1=ta.fk1 "? In SQL 2005, this will get the message "The multi-part identifier "t.fk1" could not be bound.".beacuse the result will contains duplicate data from table ta in one row.
I am returning a dataset from a method and trying to set one of the columns as Primary Key.
CategoryList.Tables[0].PrimaryKey = new DataColumn[] { CategoryList.Tables[0].Columns["CategoryNodeId"] };
Interestingly it gives me this error at run-time, These columns don't currently have unique values.
Now I perfectly know why this error should error, but there are no duplicate keys in this data column. I broke the code in between and bound the dataset to gridview to check if this column contains any duplicates and this is not the case. Here is the result set underneath. Have a look at the first column 'CategoryNodeId'.
CategoryNodeId CategoryId Name ParentCategoryNodeId [code]...
For example: INSERT INTO table (col1, col2, col3) VALUES ('value1','value2,'value3')But I would only like to insert the row if value3 isnt already present in col3 in some previous row. What is the best way to do that?And the insert command is run 50+ times in a loop (with different values each time for value3)
I currently designed a school result portal. If the students want to view their result, they input their student school number in a text box to search out their result. But this is not secured because anybody can look up any students result if you have the number which is even written on their school uniform for identification.
I have being trying to secure this result by trying to generate or code special numbers that the students will input with their school number. The special numbers will be random numbers and may be from 10 and above, it might even contain letters. How do I code this. I believe this is the best asp.net forum. I want the students to be inputing this special unique numbers and their student numbers so that there result will be avaliable to them.
On one line the Code may be OX01 and shape Hexagon for example
Then the next line the code is still OX01 but the shape is Triangle.
What I want to do is be able to pull back data for every line that is equal to a unique Code column. in the above example OX01 Hexagon would be returned but not OX01 Triangle.
I've tried using SELECT DISTINCT but it brings back all records and doesn't filter them correctly.
I've considered having another column which could have Child/Parent data so that only the parent is returned but i'm sure there must be a better way of doing this.
I have a datatable and I want to have a view on it with unique dates. The thing is that I want the date to be unique if the year,month and day are the same, I dont care for the exact time.
I now have:
Dim dtUniqueDates As System.Data.DataTable dtUniqueDates = dt.DefaultView.ToTable(True, "updatedate")
So in this case 12 february 2011 13:54 is different from 12 february 2011 15:54. But since year,month and day are the same I want them to be unique.
I have a data table with 20 records i have to get the 15 unique records randomly and have to store it in Arraylist but now problem is that how i select the 15 unique records from Data table each time .
I am generating a unique Ref number using this sql statement: SELECT REPLACE(STR(CAST(CAST(NEWID() AS binary(5)) AS bigint),12),0,0) as REF Subsequently, I need to insert this REF into sql database table in stored procedure. Here is what I did in my stored procedure:
USE [iBankRecords] GO /****** Object: StoredProcedure [dbo].[stp_addPayee] Script Date: 07/05/2010 21:57:07 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROC [dbo].[stp_addPayee] ( @CUSTID char(10), @PAYEEACCNUM nvarchar(20), @PAYEEACCTYPE char(10) , @PAYEENAME char(20), @PAYERINITIAL char(20), ) AS DECLARE @ReturnValue int INSERT INTO PAYEE (CUSTID, PAYEEACCNUM,PAYEEACCTYPE,PAYEENAME,PAYERINITIAL, REF) VALUES (@CUSTID,@PAYEEACCNUM,@PAYEEACCTYPE,@PAYEENAME,@PAYERINITIAL, REF) IF @@ERROR<>0 BEGIN PRINT 'ERROR' SET @ReturnValue=1 RETURN @RETURNVALUE END ELSE BEGIN SET @ReturnValue=0 RETURN @RETURNVALUE END
May I know how do I have generating a unique ref num and inserting the REF into the above statement?
I'm new to asp.net and I'm building a project in which I send data to a database MSSQL, I've set a constraintname on some fields that I wantto be unique, now how do I catch that error when people insert a duble and handle it with a redirectionto custom error pagehere the code just in case you need it
Dim con As New System.Data.SqlClient.SqlConnection con.ConnectionString = "Data Source=localhost;Initial Catalog=Database1;User ID=user;Password=password;TrustServerCertificate=True" Dim myCommand As New System.Data.SqlClient.SqlCommand myCommand.CommandText = "INSERT INTO serves(CategoryID,UserId,vote, Img, link, Description) VALUES('" & DropDownList1.SelectedValue & "','" & UId.Text & " ' ,1,'" & TextBox1.Text & "','" & "<a href=" + TextBox2.Text + ">" + TextBox4.Text + "</a>" & "','" & TextBox3.Text & "')" myCommand.Connection = con con.Open() myCommand.ExecuteNonQuery()
I have developed a Portal (Request submission) which sends an Email and also it updates all values to the Database. What ever values gets updated to the database, will be sent as an email message to an address. It works fine. I need a Unique number to be generated for a Request submission which has to be sent in the Email message and also it has to be updated in the database. I use SQL Server 2005 and Framework 2, C# laungauge.