473,396 Members | 1,967 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

next primary key in label control

please any urgent response.
Dear alls; (database relevent quetion)
i want to display the next availible primery key {e.g 1,2,3
(autonumbered) next 4} on the user entry form in "label" control.Thanks

Jun 7 '06 #1
6 1480
na********@yahoo.com wrote:
please any urgent response.
Dear alls; (database relevent quetion)
i want to display the next availible primery key {e.g 1,2,3
(autonumbered) next 4} on the user entry form in "label" control.Thanks

On another point, primary keys are never supposed to be used for
anything other than indexing in the database. If you're wanting to show
this kind of information, the "best" solution is to have another column
to show this kind of data.
Jun 7 '06 #2

Ray Booysen wrote:
na********@yahoo.com wrote:
please any urgent response.
Dear alls; (database relevent quetion)
i want to display the next availible primery key {e.g 1,2,3
(autonumbered) next 4} on the user entry form in "label" control.Thanks

On another point, primary keys are never supposed to be used for
anything other than indexing in the database. If you're wanting to show
this kind of information, the "best" solution is to have another column
to show this kind of data.


i don't want to show this info to the user (i will set its visible prop
to false). what
i want is to use this value to concatenate with the user picture. so
that this pic can be retrived using picname_primarykeyvalue

Jun 7 '06 #3
na********@yahoo.com wrote:
Ray Booysen wrote:
na********@yahoo.com wrote:
please any urgent response.
Dear alls; (database relevent quetion)
i want to display the next availible primery key {e.g 1,2,3
(autonumbered) next 4} on the user entry form in "label" control.Thanks

On another point, primary keys are never supposed to be used for
anything other than indexing in the database. If you're wanting to show
this kind of information, the "best" solution is to have another column
to show this kind of data.


i don't want to show this info to the user (i will set its visible prop
to false). what
i want is to use this value to concatenate with the user picture. so
that this pic can be retrived using picname_primarykeyvalue

In a multi user system, you can't guarentee what the next primary key
will be. If two users open the site at once and open the form, there
will be problems if they use the "next" primary key.
Jun 7 '06 #4
in this senerio you can not use an identity as primary key. you create a new
table

create table NextID (lastID int not null)
insert NextID values (0)

then you get the next number with a simple sql statement

declare @id int
update set @id = lastID = lastID + 1
select @id

you could also switch to a GUID as the key value type, then you can generate
them on the client when needed.

-- bruce (sqlwork.com)
<na********@yahoo.com> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
please any urgent response.
Dear alls; (database relevent quetion)
i want to display the next availible primery key {e.g 1,2,3
(autonumbered) next 4} on the user entry form in "label" control.Thanks

Jun 7 '06 #5
My method for doing this is to fire an append query then straight away
get the max ID. So long as you haven't got another transaction in the
same millisecond it should work.

e.g.

//Insert New Records into Table
strsql = "Insert Into tblMyTable (intData) Values (1)";

conn = new SqlConnection(csConnections.strConnMyConnection);
command = new SqlCommand(strsql, conn);
conn.Open();

try
{
command.ExecuteNonQuery();
}

catch
{
return "Failure";
}

finally
{
conn.Close();
}

//Get New ID
int intNewID = 0
strsql = "SELECT max(ID) FROM tblMyTable";
command = new SqlCommand(strsql, conn);
conn.Open();

reader = command.ExecuteReader();

while (reader.Read())
{
intNewID = reader.GetInt32(0);
}
conn.Close();

You can now use intNewID for part of your picture name.

Regards

Jared
na********@yahoo.com wrote:
please any urgent response.
Dear alls; (database relevent quetion)
i want to display the next availible primery key {e.g 1,2,3
(autonumbered) next 4} on the user entry form in "label" control.Thanks


Jun 7 '06 #6

Jared wrote:
My method for doing this is to fire an append query then straight away
get the max ID. So long as you haven't got another transaction in the
same millisecond it should work.

e.g.

//Insert New Records into Table
strsql = "Insert Into tblMyTable (intData) Values (1)";

conn = new SqlConnection(csConnections.strConnMyConnection);
command = new SqlCommand(strsql, conn);
conn.Open();

try
{
command.ExecuteNonQuery();
}

catch
{
return "Failure";
}

finally
{
conn.Close();
}

//Get New ID
int intNewID = 0
strsql = "SELECT max(ID) FROM tblMyTable";
command = new SqlCommand(strsql, conn);
conn.Open();

reader = command.ExecuteReader();

while (reader.Read())
{
intNewID = reader.GetInt32(0);
}
conn.Close();

You can now use intNewID for part of your picture name.

Regards

Jared


Thanks to all responses. it will solve my problem

Jun 8 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Joe | last post by:
I know that the Literal control will not render a <span> tag so I can not format its text. Other than this, what is the difference betwen the Literal control and the LiteralControl Control? How...
6
by: jcrouse | last post by:
I am rotating some text is some label controls. In the one place I use it it works fine. In the other place I use it I can't figure out the syntax. I don't really understand the event. Where it...
7
by: fniles | last post by:
In VB 6.0 in the error trapping, we can do "resume next" to continue on the next code. How can we do that in .NET with "Try", "Catch","End Try" ? Thanks
8
by: Arpan | last post by:
Consider the following code snippet (my main intention is to display the current time in a Label control as & when this ASPX page is accessed/refreshed): <script runat="server"> Class Clock...
2
by: rn5a | last post by:
Consider the following code: <script runat="server"> Sub ShowData(obj As Object, ea As EventArgs) lblDate.Text = DateTime.Now.ToString("d") lblDate.DataBind() End Sub </script> <form...
1
by: Tony Dunn | last post by:
I have inherited another developer's database (Access 2003) and with it a problem I'm struggling with. The problem is this. I have a parent-child form pair, which is populated by a table (the...
8
by: =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= | last post by:
I am working with Visual C# window and in my application I need to use a button ( NEXT) . The button should displays one panel with its objects each time it clicked. I already developed the codes...
8
by: GaryDean | last post by:
I have a Wizard page and need to affect the next and previous buttons from my code-behind. I've googled around and found two solutions, and neither appear to work. I can access the SideBarList...
16
by: pupilstuff | last post by:
hi guys i just want to perform custom paging in which at the footer of the grid view ,there must be a pager 'pervious/next with numeric' this is what i did in aspx page <asp:GridView...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.